|
|
@ -16,6 +16,7 @@ import ( |
|
|
|
"html" |
|
|
|
"html" |
|
|
|
"html/template" |
|
|
|
"html/template" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
|
|
|
|
"net/url" |
|
|
|
"regexp" |
|
|
|
"regexp" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"unicode" |
|
|
|
"unicode" |
|
|
@ -73,6 +74,25 @@ func applyMarkdown(data []byte, baseURL string, cfg *config.Config) string { |
|
|
|
return applyMarkdownSpecial(data, false, baseURL, cfg) |
|
|
|
return applyMarkdownSpecial(data, false, baseURL, cfg) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func disableYoutubeAutoplay(outHTML string) string { |
|
|
|
|
|
|
|
for _, match := range youtubeReg.FindAllString(outHTML, -1) { |
|
|
|
|
|
|
|
u, err := url.Parse(match) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
u.RawQuery = html.UnescapeString(u.RawQuery) |
|
|
|
|
|
|
|
q := u.Query() |
|
|
|
|
|
|
|
// Set Youtube autoplay url parameter, if any, to 0
|
|
|
|
|
|
|
|
if len(q["autoplay"]) == 1 { |
|
|
|
|
|
|
|
q.Set("autoplay", "0") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
u.RawQuery = q.Encode() |
|
|
|
|
|
|
|
cleanURL := u.String() |
|
|
|
|
|
|
|
outHTML = strings.Replace(outHTML, match, cleanURL, 1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return outHTML |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func applyMarkdownSpecial(data []byte, skipNoFollow bool, baseURL string, cfg *config.Config) string { |
|
|
|
func applyMarkdownSpecial(data []byte, skipNoFollow bool, baseURL string, cfg *config.Config) string { |
|
|
|
mdExtensions := 0 | |
|
|
|
mdExtensions := 0 | |
|
|
|
blackfriday.EXTENSION_TABLES | |
|
|
|
blackfriday.EXTENSION_TABLES | |
|
|
@ -108,10 +128,7 @@ func applyMarkdownSpecial(data []byte, skipNoFollow bool, baseURL string, cfg *c |
|
|
|
// Strip newlines on certain block elements that render with them
|
|
|
|
// Strip newlines on certain block elements that render with them
|
|
|
|
outHTML = blockReg.ReplaceAllString(outHTML, "<$1>") |
|
|
|
outHTML = blockReg.ReplaceAllString(outHTML, "<$1>") |
|
|
|
outHTML = endBlockReg.ReplaceAllString(outHTML, "</$1></$2>") |
|
|
|
outHTML = endBlockReg.ReplaceAllString(outHTML, "</$1></$2>") |
|
|
|
// Remove all query parameters on YouTube embed links
|
|
|
|
outHTML = disableYoutubeAutoplay(outHTML) |
|
|
|
// TODO: make this more specific. Taking the nuclear approach here to strip ?autoplay=1
|
|
|
|
|
|
|
|
outHTML = youtubeReg.ReplaceAllString(outHTML, "$1") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return outHTML |
|
|
|
return outHTML |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|