You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An HTML comment between two words draws a space in the default parser mode #636
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.
Reproduced on gravitypdf at e685435. Part of #520.
Activity
jakejackson1 commentedon Sep 30, 2026
Fixed by #637.