fb55/htmlparser2

Newlines in <script> tag content that contains strings that look like HTML tags

Zer0Divis0r opened this issue · 5 comments

HTML tags become prepended with newline even if they are inside <script> tags.
As a result, ontext parameter of parsing of line like:

<script>
$('<p>Hello</p><hr><br>Good bye');
</script>

gives:

$('
<p>Hello
</p>
<div>fff
</div>
<hr>
<br>Good bye');

Actually, even example code from the documentation gives me a different result.

Docs say the result would be:

--> Xyz
JS! Hooray!
--> var foo = '<<bar>>';
That's it?!

I am getting:

--> Xyz 
JS! Hooray!
--> var foo = '
--> <
--> <bar>>';
That's it?!

What could be the problem?

fb55 commented

Text is emitted in multiple fragments, whenever parsing might switch to a different mode. You will have to combine text nodes in your code. The same applies to comment data.

fb55 commented

Assuming this is resolved, please let me know if it isn't.

But don't you think that the documentation should reflect what the code actually does? Or at least mention that the text has to be combined?

fb55 commented

That's what the simplified in the read me is supposed to do. I'm not particularly happy with this, feel free to suggest alternative phrasing.