1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

add_mailto_subject: New rewrite function

Dinosaur Comics (qwantz.com) likes to hide jokes in mailto: links, but
miniflux's sanitizer strips those out.
This commit is contained in:
Peter De Wachter 2019-08-13 17:44:23 +02:00 committed by Frédéric Guillot
parent 77125f45cc
commit b6f3160dbc
4 changed files with 45 additions and 0 deletions

View file

@ -7,6 +7,7 @@ package rewrite // import "miniflux.app/reader/rewrite"
import (
"fmt"
"html"
"net/url"
"regexp"
"strings"
@ -43,6 +44,38 @@ func addImageTitle(entryURL, entryContent string) string {
return entryContent
}
func addMailtoSubject(entryURL, entryContent string) string {
doc, err := goquery.NewDocumentFromReader(strings.NewReader(entryContent))
if err != nil {
return entryContent
}
matches := doc.Find(`a[href^="mailto:"]`)
if matches.Length() > 0 {
matches.Each(func(i int, a *goquery.Selection) {
hrefAttr, _ := a.Attr("href")
mailto, err := url.Parse(hrefAttr)
if err != nil {
return
}
subject := mailto.Query().Get("subject")
if subject == "" {
return
}
a.AppendHtml(" [" + html.EscapeString(subject) + "]")
})
output, _ := doc.Find("body").First().Html()
return output
}
return entryContent
}
func addDynamicImage(entryURL, entryContent string) string {
doc, err := goquery.NewDocumentFromReader(strings.NewReader(entryContent))
if err != nil {