Skip to content

Commit

Permalink
CSS and JS: Make CSS and JS inclusions in Markup greedy. Fix #1240
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Dec 5, 2017
1 parent af50e44 commit 7dc1e45
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
3 changes: 2 additions & 1 deletion components/prism-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ if (Prism.languages.markup) {
pattern: /(<style[\s\S]*?>)[\s\S]*?(?=<\/style>)/i,
lookbehind: true,
inside: Prism.languages.css,
alias: 'language-css'
alias: 'language-css',
greedy: true
}
});

Expand Down
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.

3 changes: 2 additions & 1 deletion components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ if (Prism.languages.markup) {
pattern: /(<script[\s\S]*?>)[\s\S]*?(?=<\/script>)/i,
lookbehind: true,
inside: Prism.languages.javascript,
alias: 'language-javascript'
alias: 'language-javascript',
greedy: true
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion components/prism-javascript.min.js

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

6 changes: 4 additions & 2 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,8 @@ if (Prism.languages.markup) {
pattern: /(<style[\s\S]*?>)[\s\S]*?(?=<\/style>)/i,
lookbehind: true,
inside: Prism.languages.css,
alias: 'language-css'
alias: 'language-css',
greedy: true
}
});

Expand Down Expand Up @@ -743,7 +744,8 @@ if (Prism.languages.markup) {
pattern: /(<script[\s\S]*?>)[\s\S]*?(?=<\/script>)/i,
lookbehind: true,
inside: Prism.languages.javascript,
alias: 'language-javascript'
alias: 'language-javascript',
greedy: true
}
});
}
Expand Down
38 changes: 38 additions & 0 deletions tests/languages/markup!+css+javascript/issue1240.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<script>
let str = `
<style>
.foo { color: blue; }
</style>
`;
</script>

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

[

["tag", [
["tag", [
["punctuation", "<"],
"script"
]],
["punctuation", ">"]
]],
["script", [
["keyword", "let"],
" str ",
["operator", "="],
["template-string", [["string", "`\r\n\t\t<style>\r\n\t\t\t.foo { color: blue; }\r\n\t\t</style>\r\n\t`"]]],
["punctuation", ";"]
]],
["tag", [
["tag", [
["punctuation", "</"],
"script"
]],
["punctuation", ">"]
]]
]

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

Checks for Javascript usage inside Markup, using <script> tags.

0 comments on commit 7dc1e45

Please sign in to comment.