From c43c9458a95552f0a68084a91c631e9e45713a19 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 28 Nov 2019 20:11:39 -0800 Subject: Add rewrite functions: convert_text_link and nl2br --- reader/rewrite/rewriter.go | 4 ++++ reader/rewrite/rewriter_test.go | 20 ++++++++++++++++++++ reader/rewrite/rules.go | 1 + 3 files changed, 25 insertions(+) diff --git a/reader/rewrite/rewriter.go b/reader/rewrite/rewriter.go index ad1b9a3..c6b796a 100644 --- a/reader/rewrite/rewriter.go +++ b/reader/rewrite/rewriter.go @@ -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) } } diff --git a/reader/rewrite/rewriter_test.go b/reader/rewrite/rewriter_test.go index 0fd49ba..27cf425 100644 --- a/reader/rewrite/rewriter_test.go +++ b/reader/rewrite/rewriter_test.go @@ -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
B
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: http://example.org/a/b` + + if expected != output { + t.Errorf(`Not expected output: got %q instead of %q`, output, expected) + } +} diff --git a/reader/rewrite/rules.go b/reader/rewrite/rules.go index 62df1ed..c5d92fa 100644 --- a/reader/rewrite/rules.go +++ b/reader/rewrite/rules.go @@ -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", } -- cgit v1.2.3