mirror of
https://github.com/miniflux/v2.git
synced 2025-08-11 17:51:01 +00:00
Add rewrite rule to remove dom elements
This commit is contained in:
parent
9fbcfc213b
commit
93596c1218
3 changed files with 112 additions and 38 deletions
|
@ -5,10 +5,26 @@
|
|||
package rewrite // import "miniflux.app/reader/rewrite"
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseRules(t *testing.T) {
|
||||
rulesText := `add_dynamic_image,replace("article/(.*).svg"|"article/$1.png"),remove(".spam, .ads:not(.keep)")`
|
||||
expected := []rule{
|
||||
{name: "add_dynamic_image"},
|
||||
{name: "replace", args: []string{"article/(.*).svg", "article/$1.png"}},
|
||||
{name: "remove", args: []string{".spam, .ads:not(.keep)"}},
|
||||
}
|
||||
|
||||
actual := parseRules(rulesText)
|
||||
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Errorf(`Parsed rules do not match expected rules: got %v instead of %v`, actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplaceTextLinks(t *testing.T) {
|
||||
scenarios := map[string]string{
|
||||
`This is a link to example.org`: `This is a link to example.org`,
|
||||
|
@ -234,7 +250,17 @@ func TestRewriteNoScriptImageWithNoScriptTag(t *testing.T) {
|
|||
func TestRewriteReplaceCustom(t *testing.T) {
|
||||
content := `<img src="http://example.org/logo.svg"><img src="https://example.org/article/picture.svg">`
|
||||
expected := `<img src="http://example.org/logo.svg"><img src="https://example.org/article/picture.png">`
|
||||
output := Rewriter("https://example.org/artcle", content, `replace("article/(.*).svg"|"article/$1.png")`)
|
||||
output := Rewriter("https://example.org/article", content, `replace("article/(.*).svg"|"article/$1.png")`)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Not expected output: %s`, output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteRemoveCustom(t *testing.T) {
|
||||
content := `<div>Lorem Ipsum <span class="spam">I dont want to see this</span><span class="ads keep">Super important info</span></div>`
|
||||
expected := `<div>Lorem Ipsum <span class="ads keep">Super important info</span></div>`
|
||||
output := Rewriter("https://example.org/article", content, `remove(".spam, .ads:not(.keep)")`)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Not expected output: %s`, output)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue