summaryrefslogtreecommitdiff
path: root/reader/rewrite/rewriter_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'reader/rewrite/rewriter_test.go')
-rw-r--r--reader/rewrite/rewriter_test.go34
1 files changed, 33 insertions, 1 deletions
diff --git a/reader/rewrite/rewriter_test.go b/reader/rewrite/rewriter_test.go
index 8c0db6cf..04f4c657 100644
--- a/reader/rewrite/rewriter_test.go
+++ b/reader/rewrite/rewriter_test.go
@@ -4,7 +4,10 @@
package rewrite // import "miniflux.app/reader/rewrite"
-import "testing"
+import (
+ "strings"
+ "testing"
+)
func TestReplaceTextLinks(t *testing.T) {
scenarios := map[string]string{
@@ -176,3 +179,32 @@ func TestConvertTextLinkRewriteRule(t *testing.T) {
t.Errorf(`Not expected output: got %q instead of %q`, output, expected)
}
}
+
+func TestMediumImage(t *testing.T) {
+ content := `
+ <figure class="ht hu hv hw hx hy cy cz paragraph-image">
+ <div class="hz ia ib ic aj">
+ <div class="cy cz hs">
+ <div class="ii s ib ij">
+ <div class="ik il s">
+ <div class="id ie t u v if aj bk ig ih">
+ <img alt="Image for post" class="t u v if aj im in io" src="https://miro.medium.com/max/60/1*ephLSqSzQYLvb7faDwzRbw.jpeg?q=20" width="1280" height="720"/>
+ </div>
+ <img alt="Image for post" class="id ie t u v if aj c" width="1280" height="720"/>
+ <noscript>
+ <img alt="Image for post" class="t u v if aj" src="https://miro.medium.com/max/2560/1*ephLSqSzQYLvb7faDwzRbw.jpeg" width="1280" height="720" srcSet="https://miro.medium.com/max/552/1*ephLSqSzQYLvb7faDwzRbw.jpeg 276w, https://miro.medium.com/max/1104/1*ephLSqSzQYLvb7faDwzRbw.jpeg 552w, https://miro.medium.com/max/1280/1*ephLSqSzQYLvb7faDwzRbw.jpeg 640w, https://miro.medium.com/max/1400/1*ephLSqSzQYLvb7faDwzRbw.jpeg 700w" sizes="700px"/>
+ </noscript>
+ </div>
+ </div>
+ </div>
+ </div>
+ </figure>
+ `
+ expected := `<img alt="Image for post" class="t u v if aj" src="https://miro.medium.com/max/2560/1*ephLSqSzQYLvb7faDwzRbw.jpeg" width="1280" height="720" srcset="https://miro.medium.com/max/552/1*ephLSqSzQYLvb7faDwzRbw.jpeg 276w, https://miro.medium.com/max/1104/1*ephLSqSzQYLvb7faDwzRbw.jpeg 552w, https://miro.medium.com/max/1280/1*ephLSqSzQYLvb7faDwzRbw.jpeg 640w, https://miro.medium.com/max/1400/1*ephLSqSzQYLvb7faDwzRbw.jpeg 700w" sizes="700px"/>`
+ output := Rewriter("https://example.org/article", content, "fix_medium_images")
+ output = strings.TrimSpace(output)
+
+ if expected != output {
+ t.Errorf(`Not expected output: %s`, output)
+ }
+}