kostya/lexbor

Can't delete all comments from document.

MrSorcus opened this issue · 1 comments

require "lexbor"

html = <<-HTML
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Example</title>
  </head>
  <body><!-- foo --> <!-- bar --> <!-- baz --></body>
</html>
HTML

lexbor = Lexbor::Parser.new(html)
lexbor.nodes(:_em_comment).each(&.remove!)
puts lexbor.body!.to_html

Should print <body> </body>, but instead print <body><!-- bar --> <!-- baz --></body>.
Or it doesn't work like that?

this works:

nodes = lexbor.nodes(:_em_comment).to_a
nodes.each(&.remove!)
puts lexbor.body!.to_html

I think need to change example: because nodes in this line lexbor.nodes(:_em_comment).each(&.remove!) is iterator, not materialized array. And removing while iterating, something like break things.