From 515daa038346d483b145e856324581674a102f81 Mon Sep 17 00:00:00 2001 From: Philip Sampaio Date: Sat, 23 Mar 2024 13:34:04 -0300 Subject: [PATCH] Fix parsing of comments in `parse/1` (#141) Closes https://github.com/rusterlium/html5ever_elixir/issues/121 --- native/html5ever_nif/src/flat_dom.rs | 4 +++- test/html5ever_test.exs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/native/html5ever_nif/src/flat_dom.rs b/native/html5ever_nif/src/flat_dom.rs index e21aca8..d8f3adb 100644 --- a/native/html5ever_nif/src/flat_dom.rs +++ b/native/html5ever_nif/src/flat_dom.rs @@ -583,7 +583,9 @@ pub fn flat_sink_to_rec_term<'a>( NodeData::Text { contents } => { term = StrTendrilWrapper(contents).encode(env); } - NodeData::Comment { .. } => continue, + NodeData::Comment { contents } => { + term = (atoms::comment(), StrTendrilWrapper(contents)).encode(env); + } _ => unimplemented!(""), } diff --git a/test/html5ever_test.exs b/test/html5ever_test.exs index 94151e4..00d0784 100644 --- a/test/html5ever_test.exs +++ b/test/html5ever_test.exs @@ -8,9 +8,17 @@ defmodule Html5everTest do end test "parse basic html" do - html = "" + html = "

Hello

" - assert Html5ever.parse(html) == {:ok, [{"html", [], [{"head", [], []}, {"body", [], []}]}]} + assert Html5ever.parse(html) == + {:ok, + [ + {"html", [], + [ + {"head", [], []}, + {"body", [], [{"h1", [], ["Hello"]}, {:comment, " my comment "}]} + ]} + ]} end test "does not parse with not valid UTF8 binary" do