Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make all CSS inline - Class Issue

Tags:

html

css

php

inline

I found this awesome class that converts CSS style blocks to inline. However, I think it has a problem. For example, if you have the following:

<style type="text/css">
.myclass{
padding:0px;
}
<style>

<p class="myclass" style="padding-top: 40px;">Test</p>

It will convert the above to:

<p class="myclass" style="padding-top: 40px; padding:0px;">Test</p>

But the above is incorrect. It should prepend since the padding-top inline has priority as it is already inline. So it should be:

<p class="myclass" style="padding:0px; padding-top: 40px;">Test</p>

But I am struggling where to make this edit in the class. I thought it would be straightforward and I could submit it to the class creator but I am struggling.

Any ideas?

like image 956
Abs Avatar asked Aug 14 '11 15:08

Abs


1 Answers

The best solution is create an issue and get in touch with the developer. So he can fix it for others too. That's a growth of the community .

Just going through the code in a quick way what I think is before building the chunks reverse the array $properties

$properties = array_reverse ( $properties, true );
// build chunks
foreach($properties as $key => $values)

The $properties = array_reverse ( $properties, true ) which preserves the key on the top of build chunks on line 318 as linked will reverse all.

Hope that helps! Not sure whether this will bring any other issues, just try.

like image 118
Hari K T Avatar answered Sep 24 '22 16:09

Hari K T