Skip to content

Commit

Permalink
Stylus: Fixed comments breaking strings and URLs (#2361)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-itsheng committed May 6, 2020
1 parent 032910b commit 0d65d6c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
10 changes: 9 additions & 1 deletion components/prism-stylus.js
@@ -1,6 +1,13 @@
(function (Prism) {
var inside = {
'url': /url\((["']?).*?\1\)/i,
'comment': {
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
lookbehind: true
},
'url': {
pattern: /url\((["']?).*?\1\)/i,
greedy: true
},
'string': {
pattern: /("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,
greedy: true
Expand Down Expand Up @@ -78,6 +85,7 @@
'property-declaration': {
pattern: /((?:^|\{)([ \t]*))(?:[\w-]|\{[^}\r\n]+\})+(?:\s*:\s*|[ \t]+)[^{\r\n]*(?:;|[^{\r\n,](?=$)(?!(?:\r?\n|\r)(?:\{|\2[ \t]+)))/m,
lookbehind: true,
greedy: true,
inside: {
'property': {
pattern: /^[^\s:]+/,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-stylus.min.js

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

27 changes: 27 additions & 0 deletions tests/languages/stylus/property-declaration_feature.test
Expand Up @@ -10,6 +10,12 @@ background-{foo}: bar;
div
{foo} bar

comment
content 'http://www.example.com' // comment
background url(http://example.com) /* comment */
background /* comment */ url("http://example.com")
content '/* this is string not comment */'

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

[
Expand Down Expand Up @@ -44,6 +50,27 @@ div
]]
]],
" bar"
]],

["selector", ["comment"]],
["property-declaration", [
["property", ["content"]],
["string", "'http://www.example.com'"],
["comment", "// comment"]
]],
["property-declaration", [
["property", ["background"]],
["url", "url(http://example.com)"],
["comment", "/* comment */"]
]],
["property-declaration", [
["property", ["background"]],
["comment", "/* comment */"],
["url", "url(\"http://example.com\")"]
]],
["property-declaration", [
["property", ["content"]],
["string", "'/* this is string not comment */'"]
]]
]

Expand Down

0 comments on commit 0d65d6c

Please sign in to comment.