Skip to content

Commit

Permalink
Fix tokenizing !important (#1585)
Browse files Browse the repository at this point in the history
Updates the regex to ensure that when `!important` sits next
to a property with no spaces, it's still tokenized correctly.
  • Loading branch information
OlehDutchenko authored and mAAdhaTTah committed Oct 19, 2018
1 parent 1169562 commit c1d6cb8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions components/prism-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Prism.languages.css = {
greedy: true
},
'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,
'important': /\B!important\b/i,
'important': /!important\b/i,
'function': /[-a-z0-9]+(?=\()/i,
'punctuation': /[(){};:]/
};
Expand Down Expand Up @@ -49,4 +49,4 @@ if (Prism.languages.markup) {
alias: 'language-css'
}
}, Prism.languages.markup.tag);
}
}
2 changes: 1 addition & 1 deletion components/prism-css.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions examples/prism-css.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ <h2>Simple rule</h2>
<pre><code>p { color: red; }</code></pre>

<h2>Important rule</h2>
<pre><code>p { color: red !important; }</code></pre>
<pre><code>
p {
color: red !important;
line-height: normal!important;
}
p{position:absolute!important}
</code></pre>

<h2>@ rule</h2>
<pre><code>@media screen and (min-width: 100px) {}</code></pre>
Expand All @@ -25,4 +31,4 @@ <h2>String</h2>
<pre><code>content: 'foo';</code></pre>

<h2>URL</h2>
<pre><code>content: url(foo.png);</code></pre>
<pre><code>content: url(foo.png);</code></pre>
4 changes: 2 additions & 2 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ Prism.languages.css = {
greedy: true
},
'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,
'important': /\B!important\b/i,
'important': /!important\b/i,
'function': /[-a-z0-9]+(?=\()/i,
'punctuation': /[(){};:]/
};
Expand Down Expand Up @@ -889,4 +889,4 @@ Prism.languages.js = Prism.languages.javascript;

document.addEventListener('DOMContentLoaded', self.Prism.fileHighlight);

})();
})();
16 changes: 11 additions & 5 deletions tests/languages/css/important_feature.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
color: red !important;
padding: 10px 20px 30px !important;
position:absolute!important;

----------------------------------------------------

Expand All @@ -10,12 +11,17 @@ padding: 10px 20px 30px !important;
["important", "!important"],
["punctuation", ";"],
["property", "padding"],
["punctuation", ":"],
" 10px 20px 30px ",
["important", "!important"],
["punctuation", ";"]
["punctuation", ":"],
" 10px 20px 30px ",
["important", "!important"],
["punctuation", ";"],
["property", "position"],
["punctuation", ":"],
"absolute",
["important", "!important"],
["punctuation", ";"]
]

----------------------------------------------------

Checks for !important rule.
Checks for !important rule.

0 comments on commit c1d6cb8

Please sign in to comment.