Skip to content

Commit

Permalink
Simplify patterns for <style> and <script> tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Oct 6, 2015
1 parent 5ade8a5 commit 29643f4
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 146 deletions.
23 changes: 4 additions & 19 deletions components/prism-aspnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,8 @@ Prism.languages.insertBefore('aspnet', 'comment', {
// script runat="server" contains csharp, not javascript
Prism.languages.insertBefore('aspnet', Prism.languages.javascript ? 'script' : 'tag', {
'asp script': {
pattern: /<script(?=.*runat=['"]?server['"]?)[\w\W]*?>[\w\W]*?<\/script>/i,
inside: {
tag: {
pattern: /<\/?script\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|\w+))?\s*)*\/?>/i,
inside: Prism.languages.aspnet.tag.inside
},
rest: Prism.languages.csharp || {}
}
pattern: /(<script(?=.*runat=['"]?server['"]?)[\w\W]*?>)[\w\W]*?(?=<\/script>)/i,
lookbehind: true,
inside: Prism.languages.csharp || {}
}
});

// Hacks to fix eager tag matching finishing too early: <script src="<% Foo.Bar %>"> => <script src="<% Foo.Bar %>
if ( Prism.languages.aspnet.style ) {
Prism.languages.aspnet.style.inside.tag.pattern = /<\/?style\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|\w+))?\s*)*\/?>/i;
Prism.languages.aspnet.style.inside.tag.inside = Prism.languages.aspnet.tag.inside;
}
if ( Prism.languages.aspnet.script ) {
Prism.languages.aspnet.script.inside.tag.pattern = Prism.languages.aspnet['asp script'].inside.tag.pattern;
Prism.languages.aspnet.script.inside.tag.inside = Prism.languages.aspnet.tag.inside;
}
});
2 changes: 1 addition & 1 deletion components/prism-aspnet.min.js

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

11 changes: 3 additions & 8 deletions components/prism-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@ Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css
if (Prism.languages.markup) {
Prism.languages.insertBefore('markup', 'tag', {
'style': {
pattern: /<style[\w\W]*?>[\w\W]*?<\/style>/i,
inside: {
'tag': {
pattern: /<style[\w\W]*?>|<\/style>/i,
inside: Prism.languages.markup.tag.inside
},
rest: Prism.languages.css
},
pattern: /(<style[\w\W]*?>)[\w\W]*?(?=<\/style>)/i,
lookbehind: true,
inside: Prism.languages.css,
alias: 'language-css'
}
});
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.

11 changes: 3 additions & 8 deletions components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@ Prism.languages.insertBefore('javascript', 'class-name', {
if (Prism.languages.markup) {
Prism.languages.insertBefore('markup', 'tag', {
'script': {
pattern: /<script[\w\W]*?>[\w\W]*?<\/script>/i,
inside: {
'tag': {
pattern: /<script[\w\W]*?>|<\/script>/i,
inside: Prism.languages.markup.tag.inside
},
rest: Prism.languages.javascript
},
pattern: /(<script[\w\W]*?>)[\w\W]*?(?=<\/script>)/i,
lookbehind: true,
inside: Prism.languages.javascript,
alias: 'language-javascript'
}
});
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.

22 changes: 6 additions & 16 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,14 +518,9 @@ Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css
if (Prism.languages.markup) {
Prism.languages.insertBefore('markup', 'tag', {
'style': {
pattern: /<style[\w\W]*?>[\w\W]*?<\/style>/i,
inside: {
'tag': {
pattern: /<style[\w\W]*?>|<\/style>/i,
inside: Prism.languages.markup.tag.inside
},
rest: Prism.languages.css
},
pattern: /(<style[\w\W]*?>)[\w\W]*?(?=<\/style>)/i,
lookbehind: true,
inside: Prism.languages.css,
alias: 'language-css'
}
});
Expand Down Expand Up @@ -621,14 +616,9 @@ Prism.languages.insertBefore('javascript', 'class-name', {
if (Prism.languages.markup) {
Prism.languages.insertBefore('markup', 'tag', {
'script': {
pattern: /<script[\w\W]*?>[\w\W]*?<\/script>/i,
inside: {
'tag': {
pattern: /<script[\w\W]*?>|<\/script>/i,
inside: Prism.languages.markup.tag.inside
},
rest: Prism.languages.javascript
},
pattern: /(<script[\w\W]*?>)[\w\W]*?(?=<\/script>)/i,
lookbehind: true,
inside: Prism.languages.javascript,
alias: 'language-javascript'
}
});
Expand Down
44 changes: 22 additions & 22 deletions tests/languages/markup!+css/css_inclusion.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@ foo {
----------------------------------------------------

[
["style", [
["tag", [
["tag", [
["tag", [
["punctuation", "<"],
"style"
]],
["attr-name", [
"type"
]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"text/css",
["punctuation", "\""]
]],
["punctuation", ">"]
["punctuation", "<"],
"style"
]],
["attr-name", [
"type"
]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"text/css",
["punctuation", "\""]
]],
["punctuation", ">"]
]],
["style", [
["selector", "foo"],
["punctuation", "{"],
["property", "bar"],
["punctuation", ":"],
" baz",
["punctuation", ";"],
["punctuation", "}"],
["punctuation", "}"]
]],
["tag", [
["tag", [
["tag", [
["punctuation", "</"],
"style"
]],
["punctuation", ">"]
]]
["punctuation", "</"],
"style"
]],
["punctuation", ">"]
]],

["tag", [
Expand Down
74 changes: 38 additions & 36 deletions tests/languages/markup!+javascript/javascript_inclusion.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,53 @@
----------------------------------------------------

[
["script", [

["tag", [
["tag", [
["tag", [
["punctuation", "<"],
"script"
]],
["attr-name", [
"type"
]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"text/javascript",
["punctuation", "\""]
]],
["punctuation", ">"]
["punctuation", "<"],
"script"
]],
["attr-name", [
"type"
]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"text/javascript",
["punctuation", "\""]
]],
["punctuation", ">"]
]],
["script", [
["function", "foo"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ")"]
]],
["tag", [
["tag", [
["tag", [
["punctuation", "</"],
"script"
]],
["punctuation", ">"]
]]
["punctuation", "</"],
"script"
]],
["punctuation", ">"]
]],
["script", [

["tag", [
["tag", [
["tag", [
["punctuation", "<"],
"script"
]],
["punctuation", ">"]
["punctuation", "<"],
"script"
]],
["string", "\"foo bar\""],
["punctuation", ">"]
]],
["script", [
["string", "\"foo bar\""]
]],
["tag", [
["tag", [
["tag", [
["punctuation", "</"],
"script"
]],
["punctuation", ">"]
]]
]]
["punctuation", "</"],
"script"
]],
["punctuation", ">"]
]]
]

----------------------------------------------------
Expand Down
69 changes: 35 additions & 34 deletions tests/languages/markup+javascript+csharp+aspnet/script_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,49 @@
----------------------------------------------------

[
["tag", [
["tag", [
["punctuation", "<"],
"script"
]],
["attr-name", [
"runat"
]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"server",
["punctuation", "\""]
]],
["punctuation", ">"]
]],
["asp script", [
["preprocessor", "#foo"]
]],
["tag", [
["tag", [
["tag", [
["punctuation", "<"],
"script"
]],
["attr-name", [
"runat"
]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"server",
["punctuation", "\""]
]],
["punctuation", ">"]
["punctuation", "</"],
"script"
]],
["preprocessor", "#foo"],
["punctuation", ">"]
]],

["tag", [
["tag", [
["tag", [
["punctuation", "</"],
"script"
]],
["punctuation", ">"]
]]
["punctuation", "<"],
"script"
]],
["punctuation", ">"]
]],
["script", [
["regex", "/foo/"]
]],
["tag", [
["tag", [
["tag", [
["punctuation", "<"],
"script"
]],
["punctuation", ">"]
["punctuation", "</"],
"script"
]],
["regex", "/foo/"],
["tag", [
["tag", [
["punctuation", "</"],
"script"
]],
["punctuation", ">"]
]]
["punctuation", ">"]
]]
]

Expand Down

0 comments on commit 29643f4

Please sign in to comment.