Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline CSS always commented by HeadStyle ViewHelper #6

Closed
weierophinney opened this issue Dec 31, 2019 · 1 comment · Fixed by #209
Closed

Inline CSS always commented by HeadStyle ViewHelper #6

weierophinney opened this issue Dec 31, 2019 · 1 comment · Fixed by #209

Comments

@weierophinney
Copy link
Member

It looks like the inline style definition is not correctly printed by HeadStyle view helper.

Considering the following one:

<?php $this->headStyle()->captureStart(); ?>
@media only screen and (max-width: 620px) {

div[class*="pd-left20"]{padding:0 0 0 20px !important;}
td[class*="resetPadding"]{padding:0 0 0 0 !important;}
td[class*="padding20"]{padding:20px 0 20px 0 !important;}

}
<?php $this->headStyle()->captureEnd(); ?>

The whole block will be commented out.

I tried disabling auto escaper but escaping is hardcoded into HeadStyle implementation.

Actually, after a deep look in the code, I don't get why CSS content is always commented via <!-- -->:

[0]

 $html = '<style type="text/css"' . $attrString . '>' . PHP_EOL
            . $escapeStart . $indent . $item->content . PHP_EOL . $escapeEnd
            . '</style>';

$escapeStart and $escapeEnd can be null only for conditional CSS which is not a regular use case.

The examples from documentation are giving me similar commented output. [1]

[0] https://github.com/zendframework/zend-view/blob/master/src/Helper/HeadStyle.php#L328
[1] https://docs.zendframework.com/zend-view/helpers/head-style/#capturing-style-declarations


Originally posted by @tworzenieweb at zendframework/zend-view#165

@weierophinney
Copy link
Member Author

@tworzenieweb

The whole block will be commented out.

The comments are used for backward compatibility in old browsers and are ignored by CSS.

But today these comments are obsolete and can be removed without problems.


Originally posted by @froschdesign at zendframework/zend-view#165 (comment)

gsteel added a commit to gsteel/laminas-view that referenced this issue Jul 19, 2023
Closes laminas#6

It is not necessary to comment CSS within style tags so output has changed from:

`<style><!-- a {} --></style>` to `<style> a {} </style>`

The `<style media="">` attribute was restricted to list of pre-defined values such as `[screen, print, braille]`, when in reality the media attribute can contain any sort of media query such as `screen and (min-width: 10rem)`. These restrictions have been removed the property listing those restrictions deprecated.

Additionally, if the `media` attribute is an array containing non-string values, an exception will be thrown. Previously, there would have been a type error.

Style tag attributes not present in a list of 'allowed' attributes are silently ignored. This list has been updated to include the `nonce` attribute.

Adds `@method setIndent` which magically proxies to the container.

Adds probably desirable behaviour where if the user provides an empty string, i.e. `$this->headStyle()->appendStyle('');`, then no markup will be output for that item.

Lots of type inference improvements and some test improvements.

Signed-off-by: George Steel <george@net-glue.co.uk>
gsteel added a commit to gsteel/laminas-view that referenced this issue Jul 19, 2023
Closes laminas#6

It is not necessary to comment CSS within style tags so output has changed from:

`<style><!-- a {} --></style>` to `<style> a {} </style>`

The `<style media="">` attribute was restricted to list of pre-defined values such as `[screen, print, braille]`, when in reality the media attribute can contain any sort of media query such as `screen and (min-width: 10rem)`. These restrictions have been removed the property listing those restrictions deprecated.

Additionally, if the `media` attribute is an array containing non-string values, an exception will be thrown. Previously, there would have been a type error.

Style tag attributes not present in a list of 'allowed' attributes are silently ignored. This list has been updated to include the `nonce` attribute.

Adds `@method setIndent` which magically proxies to the container.

Adds probably desirable behaviour where if the user provides an empty string, i.e. `$this->headStyle()->appendStyle('');`, then no markup will be output for that item.

Lots of type inference improvements and some test improvements.

Signed-off-by: George Steel <george@net-glue.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant