Bug: `removeComments` also deletes any text content that follows the comment
jake-low opened this issue · comments
Found in version 0.2.8 (latest).
When using the removeComments
feature, text content which follows a comment is also deleted. Text which precedes a comment is unaffected.
Input:
<div id="foo">
Text before a comment. <!-- a comment -->
</div>
<div id="bar">
<!-- a comment --> Text after a comment.
</div>
<div id="baz">
Some text which... <!-- a comment --> ...surrounds a comment.
</div>
Processor:
htmlnano
.process(html, { removeComments: true }, {})
.then(result => console.log(result.html))
Expected output:
<div id="foo">
Text before a comment.
</div>
<div id="bar">
Text after a comment.
</div>
<div id="baz">
Some text which... ...surrounds a comment.
</div>
Output:
<div id="foo">
Text before a comment. </div>
<div id="bar">
</div>
<div id="baz">
Some text which... </div>
Text content which followed a comment is missing from the output above. (Note: the \n
chars preceding the closing </div>
tags are also missing, which is odd, but unrelated).
The root cause of this bug is in posthtml-parser, and I've opened a PR to fix it there. Hopefully that fix can make its way downstream to htmlnano before too long.
Thanks for the report! Can you please ping me once your fix would be released? I'll try to issue a new htmlnano
release ASAP then.
Sure, I can do that. 👍
The issue should be solved now, as the upstream already merged the PR and has released a newer version.
This issue is happening with htmlnano@2.1.0
, did it went broken on upstream?
for this piece of code:
<div class="duplicate-conflict info-txt info-txt-fn">
<!-- Replace %1 by <strong>filename.ext</strong> !-->
[$16486]
</div>
That [$16486]
is wrongly removed.
@maltsev ? 🙂
@diegocr I tested it with the latest htmlnano@2.1.1
and it works correctly. [$16486]
isn't removed.
Thanks, is that because of #278 ? saw the release and was wondering, although by the code-changes doesn't seem so, anyway will re-test using that version whenever we update npm packages in my org.
I think so. As #278 is the only change made between 2.1.0 and 2.1.1.