A <style> or <link> inside <!--mpdf … mpdf--> is applied whatever its media attribute says #813
Description
A <style> or <link> inside <!--mpdf … mpdf--> is applied whatever its media says.
$mpdf = new \Mpdf\Mpdf(['CSSselectMedia' => 'print']);
$mpdf->WriteHTML('<!--mpdf <style media="screen">p { color: red; }</style> mpdf--><p>x</p>');The paragraph is red. Without the <!--mpdf wrapper it is not. This happens on gravitypdf (b5ede4c) and on #800.
Cause. CssParser::parse() filters by medium before HTML comments are removed. The skip in Tags::startTagPattern() reads <!--mpdf <style media="screen"> as one other tag, so the <style> is never seen. Once the markers are gone, the second pass collects the stylesheet without checking its medium.
Suggested change (from the altitude review of #800):
- Only the comment-marker step has to run before
removeHtmlComments(). CssLoader::collectStylesheets()would callMediaQueryProcessor::isForSelectedMedium()on each<style>,<link>and nested<link>as it finds them, dropping the ones for other media.- The first pass then becomes a plain
CommentParser::removeCommentsFromStyleBlocks().
That also removes the second copy of the "<link> written inside a <style> block's text" handling. Since then lives only in collectStylesheets(), where CssParser::filterStylesheetsByMedium() currently has to stay in step with it.
This changes output: stylesheets inside <!--mpdf … mpdf--> would start being filtered by medium. It needs a changelog entry and a snapshot.
Activity