Skip to content

Commit

Permalink
Markup: Regexp optimisation + fix punctuation inside attr-value
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Oct 22, 2017
1 parent f489a1e commit ea380c6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
12 changes: 9 additions & 3 deletions components/prism-markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Prism.languages.markup = {
'doctype': /<!DOCTYPE[\s\S]+?>/i,
'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
'tag': {
pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\s\S])*\1|[^\s'">=]+))?)*\s*\/?>/i,
pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/i,
inside: {
'tag': {
pattern: /^<\/?[^\s>\/]+/i,
Expand All @@ -14,9 +14,15 @@ Prism.languages.markup = {
}
},
'attr-value': {
pattern: /=(?:('|")[\s\S]*?(\1)|[^\s>]+)/i,
pattern: /=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+)/i,
inside: {
'punctuation': /[=>"']/
'punctuation': [
/^=/,
{
pattern: /(^|[^\\])["']/,
lookbehind: true
}
]
}
},
'punctuation': /\/?>/,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-markup.min.js

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

12 changes: 9 additions & 3 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ Prism.languages.markup = {
'doctype': /<!DOCTYPE[\s\S]+?>/i,
'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
'tag': {
pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\s\S])*\1|[^\s'">=]+))?)*\s*\/?>/i,
pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/i,
inside: {
'tag': {
pattern: /^<\/?[^\s>\/]+/i,
Expand All @@ -554,9 +554,15 @@ Prism.languages.markup = {
}
},
'attr-value': {
pattern: /=(?:('|")[\s\S]*?(\1)|[^\s>]+)/i,
pattern: /=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+)/i,
inside: {
'punctuation': /[=>"']/
'punctuation': [
/^=/,
{
pattern: /(^|[^\\])["']/,
lookbehind: true
}
]
}
},
'punctuation': /\/?>/,
Expand Down
3 changes: 1 addition & 2 deletions tests/languages/csharp+aspnet/directive_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"ProductDetails.aspx?productID",
["punctuation", "="],
"ProductDetails.aspx?productID=",
["directive tag", [
["directive tag", "<%#:"],
"Item",
Expand Down
6 changes: 1 addition & 5 deletions tests/languages/django/property_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
["punctuation", "<"],
"a"
]],
["attr-name", ["href"]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""]
]],
["attr-name", ["href=\""]],
["property", [
"{{ ",
["variable", "story"],
Expand Down
18 changes: 18 additions & 0 deletions tests/languages/markup/tag_attribute_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
bar
baz">
<div foo:bar=42>
<div foo="=\"=">

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

Expand Down Expand Up @@ -83,6 +84,23 @@ baz">
"42"
]],
["punctuation", ">"]
]],

["tag", [
["tag", [
["punctuation", "<"],
"div"
]],
["attr-name", [
"foo"
]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"=\\\"=",
["punctuation", "\""]
]],
["punctuation", ">"]
]]
]

Expand Down

0 comments on commit ea380c6

Please sign in to comment.