Skip to content

Commit 0b10fd0

Browse files
committed
Twig: Regexp optimisation and simplification + don't use captures if not needed
1 parent 08139ad commit 0b10fd0

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

components/prism-twig.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@ Prism.languages.twig = {
44
pattern: /\{\{[\s\S]*?\}\}|\{%[\s\S]*?%\}/,
55
inside: {
66
'ld': {
7-
pattern: /^(?:\{\{\-?|\{%\-?\s*\w+)/,
7+
pattern: /^(?:\{\{-?|\{%-?\s*\w+)/,
88
inside: {
9-
'punctuation': /^(?:\{\{|\{%)\-?/,
9+
'punctuation': /^(?:\{\{|\{%)-?/,
1010
'keyword': /\w+/
1111
}
1212
},
1313
'rd': {
14-
pattern: /\-?(?:%\}|\}\})$/,
14+
pattern: /-?(?:%\}|\}\})$/,
1515
inside: {
1616
'punctuation': /.*/
1717
}
1818
},
1919
'string': {
20-
pattern: /("|')(?:\\?.)*?\1/,
20+
pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
2121
inside: {
2222
'punctuation': /^['"]|['"]$/
2323
}
2424
},
2525
'keyword': /\b(?:even|if|odd)\b/,
2626
'boolean': /\b(?:true|false|null)\b/,
27-
'number': /\b-?(?:0x[\dA-Fa-f]+|\d*\.?\d+([Ee][-+]?\d+)?)\b/,
27+
'number': /\b-?(?:0x[\dA-Fa-f]+|\d*\.?\d+(?:[Ee][-+]?\d+)?)\b/,
2828
'operator': [
2929
{
30-
pattern: /(\s)(?:and|b\-and|b\-xor|b\-or|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/,
30+
pattern: /(\s)(?:and|b-and|b-xor|b-or|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/,
3131
lookbehind: true
3232
},
3333
/[=<>]=?|!=|\*\*?|\/\/?|\?:?|[-+~%|]/
3434
],
35-
'property': /\b[a-zA-Z_][a-zA-Z0-9_]*\b/,
35+
'property': /\b[a-zA-Z_]\w*\b/,
3636
'punctuation': /[()\[\]{}:.,]/
3737
}
3838
},

components/prism-twig.min.js

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

0 commit comments

Comments
 (0)