An HTML comment between two words draws a space in the default parser mode #636
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
An HTML comment between two words draws a space in the default parser mode, but not in HTML_BODY mode. A browser draws no space.
$mpdf->WriteHTML('<p>a<!-- x -->b</p>'); // draws "a b"
$mpdf->WriteHTML('<p>a<!-- x -->b</p>', HTMLParserMode::HTML_BODY); // draws "ab"In the default mode, CssManager::ReadCSS() calls CommentParser::removeHtmlComments(), and that replaces each comment with a space:
$html = preg_replace('/<!--.*?-->/s', ' ', $html);In HTML_BODY mode that reader does not run, and AdjustHTML() removes comments without leaving anything in their place.
The same space makes <p><!-- x --></p> hold white space, so p:empty (#537, #634) does not match it in the default mode, although it matches in body mode and in a browser.
Replacing the comment with nothing, as a browser does, would make both modes agree. It changes the spacing of documents that put a comment between two words.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
jakejackson1 commentedon Sep 30, 2026
Fixed by #637.