Skip to content

Commit c1d6cb8

Browse files
OlehDutchenkomAAdhaTTah
authored andcommitted
Fix tokenizing !important (#1585)
Updates the regex to ensure that when `!important` sits next to a property with no spaces, it's still tokenized correctly.
1 parent 1169562 commit c1d6cb8

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

components/prism-css.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Prism.languages.css = {
1414
greedy: true
1515
},
1616
'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,
17-
'important': /\B!important\b/i,
17+
'important': /!important\b/i,
1818
'function': /[-a-z0-9]+(?=\()/i,
1919
'punctuation': /[(){};:]/
2020
};
@@ -49,4 +49,4 @@ if (Prism.languages.markup) {
4949
alias: 'language-css'
5050
}
5151
}, Prism.languages.markup.tag);
52-
}
52+
}

components/prism-css.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-css.html

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ <h2>Simple rule</h2>
77
<pre><code>p { color: red; }</code></pre>
88

99
<h2>Important rule</h2>
10-
<pre><code>p { color: red !important; }</code></pre>
10+
<pre><code>
11+
p {
12+
color: red !important;
13+
line-height: normal!important;
14+
}
15+
p{position:absolute!important}
16+
</code></pre>
1117

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

2733
<h2>URL</h2>
28-
<pre><code>content: url(foo.png);</code></pre>
34+
<pre><code>content: url(foo.png);</code></pre>

prism.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ Prism.languages.css = {
647647
greedy: true
648648
},
649649
'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,
650-
'important': /\B!important\b/i,
650+
'important': /!important\b/i,
651651
'function': /[-a-z0-9]+(?=\()/i,
652652
'punctuation': /[(){};:]/
653653
};
@@ -889,4 +889,4 @@ Prism.languages.js = Prism.languages.javascript;
889889

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

892-
})();
892+
})();
+11-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
color: red !important;
22
padding: 10px 20px 30px !important;
3+
position:absolute!important;
34

45
----------------------------------------------------
56

@@ -10,12 +11,17 @@ padding: 10px 20px 30px !important;
1011
["important", "!important"],
1112
["punctuation", ";"],
1213
["property", "padding"],
13-
["punctuation", ":"],
14-
" 10px 20px 30px ",
15-
["important", "!important"],
16-
["punctuation", ";"]
14+
["punctuation", ":"],
15+
" 10px 20px 30px ",
16+
["important", "!important"],
17+
["punctuation", ";"],
18+
["property", "position"],
19+
["punctuation", ":"],
20+
"absolute",
21+
["important", "!important"],
22+
["punctuation", ";"]
1723
]
1824

1925
----------------------------------------------------
2026

21-
Checks for !important rule.
27+
Checks for !important rule.

0 commit comments

Comments
 (0)