I have some html and I need to modify some content. I tried to use Floki.attr, but on some specific html structure, the resulting tree have nodes with another order.
I have a testcase to illustrate the issue:
test "changing attribute dontt change the order of nodes" do
html = ~s(<p>a<em>b</em>c<a href="z">d</a></p><p>e</p><p><a href="f"><strong>g</strong></a>.<em>h</em>i</p><p><strong>j</strong>k<a href="m">n</a>o</p><p><em>p</em>q<em>r</em>s<a href="t">u</a></p>)
result =
html
|> Floki.attr("a", "href", fn href ->
href
end)
|> Floki.raw_html()
assert result == html
end
1) test changing attribute don't change the order of nodes (FlokiTest)
test/floki_test.exs:1068
Assertion with == failed
code: assert result == html
left: "<p><em>p</em>q<em>r</em>s<a href=\"t\">u</a></p><p>e</p><p>a<em>b</em>c<a href=\"z\">d</a></p><p><a href=\"f\"><strong>g</strong></a>.<em>h</em>i</p><p><strong>j</strong>k<a href=\"m\">n</a>o</p>"
right: "<p>a<em>b</em>c<a href=\"z\">d</a></p><p>e</p><p><a href=\"f\"><strong>g</strong></a>.<em>h</em>i</p><p><strong>j</strong>k<a href=\"m\">n</a>o</p><p><em>p</em>q<em>r</em>s<a href=\"t\">u</a></p>"
stacktrace:
test/floki_test.exs:1076: (test)
I tried to fix the issue, but I struggle on the tree -> tuple conversion. Do you have any idea ?
I have some html and I need to modify some content. I tried to use
Floki.attr
, but on some specific html structure, the resulting tree have nodes with another order.I have a testcase to illustrate the issue:
I tried to fix the issue, but I struggle on the tree -> tuple conversion. Do you have any idea ?