Skip to content

Commit 515daa0

Browse files
authored
Fix parsing of comments in parse/1 (#141)
Closes #121
1 parent af4791f commit 515daa0

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

native/html5ever_nif/src/flat_dom.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,9 @@ pub fn flat_sink_to_rec_term<'a>(
583583
NodeData::Text { contents } => {
584584
term = StrTendrilWrapper(contents).encode(env);
585585
}
586-
NodeData::Comment { .. } => continue,
586+
NodeData::Comment { contents } => {
587+
term = (atoms::comment(), StrTendrilWrapper(contents)).encode(env);
588+
}
587589
_ => unimplemented!(""),
588590
}
589591

test/html5ever_test.exs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ defmodule Html5everTest do
88
end
99

1010
test "parse basic html" do
11-
html = "<html><head></head><body></body></html>"
11+
html = "<html><head></head><body><h1>Hello</h1><!-- my comment --></body></html>"
1212

13-
assert Html5ever.parse(html) == {:ok, [{"html", [], [{"head", [], []}, {"body", [], []}]}]}
13+
assert Html5ever.parse(html) ==
14+
{:ok,
15+
[
16+
{"html", [],
17+
[
18+
{"head", [], []},
19+
{"body", [], [{"h1", [], ["Hello"]}, {:comment, " my comment "}]}
20+
]}
21+
]}
1422
end
1523

1624
test "does not parse with not valid UTF8 binary" do

0 commit comments

Comments
 (0)