Add rewrite functions: convert_text_link and nl2br
This commit is contained in:
parent
90064a8cf0
commit
c43c9458a9
3 changed files with 25 additions and 0 deletions
|
@ -35,6 +35,10 @@ func Rewriter(entryURL, entryContent, customRewriteRules string) string {
|
|||
entryContent = addYoutubeVideo(entryURL, entryContent)
|
||||
case "add_pdf_download_link":
|
||||
entryContent = addPDFLink(entryURL, entryContent)
|
||||
case "nl2br":
|
||||
entryContent = replaceLineFeeds(entryContent)
|
||||
case "convert_text_link":
|
||||
entryContent = replaceTextLinks(entryContent)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -156,3 +156,23 @@ func TestRewriteWithUnknownLazyNoScriptImage(t *testing.T) {
|
|||
t.Errorf(`Not expected output: got "%s" instead of "%s"`, output, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewLineRewriteRule(t *testing.T) {
|
||||
description := "A\nB\nC"
|
||||
output := Rewriter("https://example.org/article", description, "nl2br")
|
||||
expected := `A<br>B<br>C`
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Not expected output: got %q instead of %q`, output, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertTextLinkRewriteRule(t *testing.T) {
|
||||
description := "Test: http://example.org/a/b"
|
||||
output := Rewriter("https://example.org/article", description, "convert_text_link")
|
||||
expected := `Test: <a href="http://example.org/a/b">http://example.org/a/b</a>`
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Not expected output: got %q instead of %q`, output, expected)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,4 +28,5 @@ var predefinedRules = map[string]string{
|
|||
"treelobsters.com": "add_image_title",
|
||||
"youtube.com": "add_youtube_video",
|
||||
"xkcd.com": "add_image_title",
|
||||
"framatube.org": "nl2br,convert_text_link",
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue