diff --git a/locale/translations.go b/locale/translations.go index df26da17..5c070cbe 100755 --- a/locale/translations.go +++ b/locale/translations.go @@ -754,8 +754,8 @@ var translations = map[string]string{ "error.feed_mandatory_fields": "L'URL et la catégorie sont obligatoire.", "error.user_mandatory_fields": "Le nom d'utilisateur est obligatoire.", "form.feed.label.title": "Titre", - "form.feed.label.site_url": "URL du flux", - "form.feed.label.feed_url": "URL du site web", + "form.feed.label.site_url": "URL du site web", + "form.feed.label.feed_url": "URL du flux", "form.feed.label.category": "Catégorie", "form.feed.label.crawler": "Récupérer le contenu original", "form.feed.label.feed_username": "Nom d'utilisateur du flux", @@ -1993,7 +1993,7 @@ var translations = map[string]string{ var translationsChecksums = map[string]string{ "de_DE": "099dea24a10c4f842674db2ae44f99e99b9c880a6f83e3a42502603fa228fd32", "en_US": "c23d1f16d1dbea72c1e1ba558c7a9c25e0ee8ffda420d50c998efe2fb4d9aa55", - "fr_FR": "b123c66c61cda3ae4a978465b7a0e332a83cf386032e1df11c033ed8def9203c", + "fr_FR": "a5afa30bb63cba48fe0c2114a5e0bcb62dee7f1df0eb5748524decd280c80970", "nl_NL": "b1e548c2b21f013b1b54a07df7df7c06c776cbd7d26fc1fed288bd6970e99c3c", "pl_PL": "8cb856dede8b4f75e4c6aeb0a45f09507c5010f782692e887aae357e99674218", "ru_RU": "0544db0800811fc678521b2e9a7141380919b9ae259b3158524619bf120600ab", diff --git a/locale/translations/fr_FR.json b/locale/translations/fr_FR.json index 3a7371c7..5138b3da 100644 --- a/locale/translations/fr_FR.json +++ b/locale/translations/fr_FR.json @@ -191,8 +191,8 @@ "error.feed_mandatory_fields": "L'URL et la catégorie sont obligatoire.", "error.user_mandatory_fields": "Le nom d'utilisateur est obligatoire.", "form.feed.label.title": "Titre", - "form.feed.label.site_url": "URL du flux", - "form.feed.label.feed_url": "URL du site web", + "form.feed.label.site_url": "URL du site web", + "form.feed.label.feed_url": "URL du flux", "form.feed.label.category": "Catégorie", "form.feed.label.crawler": "Récupérer le contenu original", "form.feed.label.feed_username": "Nom d'utilisateur du flux", diff --git a/reader/rewrite/rewrite_functions.go b/reader/rewrite/rewrite_functions.go index fee2a85e..6ce96937 100644 --- a/reader/rewrite/rewrite_functions.go +++ b/reader/rewrite/rewrite_functions.go @@ -13,8 +13,9 @@ import ( ) var ( - youtubeRegex = regexp.MustCompile(`youtube\.com/watch\?v=(.*)`) - imgRegex = regexp.MustCompile(`]+>`) + youtubeRegex = regexp.MustCompile(`youtube\.com/watch\?v=(.*)`) + imgRegex = regexp.MustCompile(`]+>`) + textLinkRegex = regexp.MustCompile(`(?mi)(\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])`) ) func addImageTitle(entryURL, entryContent string) string { @@ -108,7 +109,7 @@ func addYoutubeVideo(entryURL, entryContent string) string { if len(matches) == 2 { video := `` - return video + "

" + entryContent + "

" + return video + "

" + replaceLineFeeds(replaceTextLinks(entryContent)) + "

" } return entryContent } @@ -119,3 +120,11 @@ func addPDFLink(entryURL, entryContent string) string { } return entryContent } + +func replaceTextLinks(input string) string { + return textLinkRegex.ReplaceAllString(input, `${1}`) +} + +func replaceLineFeeds(input string) string { + return strings.Replace(input, "\n", "
", -1) +} diff --git a/reader/rewrite/rewriter_test.go b/reader/rewrite/rewriter_test.go index 7ceb0dc9..fe37b539 100644 --- a/reader/rewrite/rewriter_test.go +++ b/reader/rewrite/rewriter_test.go @@ -6,6 +6,26 @@ package rewrite // import "miniflux.app/reader/rewrite" import "testing" +func TestReplaceTextLinks(t *testing.T) { + scenarios := map[string]string{ + `This is a link to example.org`: `This is a link to example.org`, + `This is a link to ftp://example.org`: `This is a link to ftp://example.org`, + `This is a link to www.example.org`: `This is a link to www.example.org`, + `This is a link to http://example.org`: `This is a link to http://example.org`, + `This is a link to http://example.org, end of sentence.`: `This is a link to http://example.org, end of sentence.`, + `This is a link to https://example.org`: `This is a link to https://example.org`, + `This is a link to https://www.example.org/path/to?q=s`: `This is a link to https://www.example.org/path/to?q=s`, + `This is a link to https://example.org/index#hash-tag, http://example.org/.`: `This is a link to https://example.org/index#hash-tag, http://example.org/.`, + } + + for input, expected := range scenarios { + actual := replaceTextLinks(input) + if actual != expected { + t.Errorf(`Unexpected link replacement, got "%s" instead of "%s"`, actual, expected) + } + } +} + func TestRewriteWithNoMatchingRule(t *testing.T) { output := Rewriter("https://example.org/article", `Some text.`, ``) expected := `Some text.` @@ -16,8 +36,8 @@ func TestRewriteWithNoMatchingRule(t *testing.T) { } func TestRewriteWithYoutubeLink(t *testing.T) { - output := Rewriter("https://www.youtube.com/watch?v=1234", `Video Description`, ``) - expected := `

Video Description

` + output := Rewriter("https://www.youtube.com/watch?v=1234", "Video Description\nhttp://example.org/path", ``) + expected := `

Video Description
http://example.org/path

` if expected != output { t.Errorf(`Not expected output: got "%s" instead of "%s"`, output, expected)