FFFF [pull] main from miniflux:main by pull[bot] · Pull Request #346 · suhaoGe/miniflux · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions internal/reader/rewrite/content_rewrite_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,11 @@ func removeTables(entryContent string) string {
break
}

loopElement.Parent().AppendHtml(innerHtml)
loopElement.Remove()
// Replace the element with its own content in place, so the
// surrounding content keeps its original document order.
// Appending to the parent would move the unwrapped content to
// the end of the parent instead.
loopElement.ReplaceWithHtml(innerHtml)
}
}

Expand Down
23 changes: 23 additions & 0 deletions internal/reader/rewrite/content_rewrite_test.go
< 60BF td id="diff-66d1710478520d11c95d3c0171fab17c63d413a030e0fe334553f133ddd4bbacR978" data-line-number="978" class="blob-num blob-num-addition js-linkable-line-number js-blob-rnum">
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,29 @@ func TestRewriteRemoveTables(t *testing.T) {
}
}

func TestRewriteRemoveTablesKeepsSurroundingContentOrder(t *testing.T) {
// Regression test for https://github.com/miniflux/v2/issues/3110
// When a table is unwrapped, its content and the content surrounding it
// must keep their original document order. Previously the unwrapped
// content was appended to the end of the parent, so anything after the
// table (and the table content itself) ended up reordered.
controlEntry := &model.Entry{
URL: "https://example.org/article",
Title: `A title`,
Content: `<h1>Header</h1><p>Intro</p><img src="https://example.org/image.png"/><p>Outro</p>`,
}
testEntry := &model.Entry{
URL: "https://example.org/article",
Title: `A title`,
Content: `<h1>Header</h1><table><tbody><tr><td><p>Intro</p><img src="https://example.org/image.png"/></td></tr></tbody></table><p>Outro</p>`,
}
ApplyContentRewriteRules(testEntry, `remove_tables`)

if !reflect.DeepEqual(testEntry, controlEntry) {
t.Errorf(`Not expected output: got "%+v" instead of "%+v"`, testEntry, controlEntry)
}
}

func TestRemoveClickbait(t *testing.T) {
controlEntry := &model.Entry{
URL: "https://example.org/article",
Expand Down
Loading
0