Skip to content

Commit aa426b0

Browse files
committed
LaTeX: Regexp optimisation and simplification
1 parent 12ff8dc commit aa426b0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

components/prism-latex.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function(Prism) {
2-
var funcPattern = /\\([^a-z()[\]]|[a-z\*]+)/i,
2+
var funcPattern = /\\(?:[^a-z()[\]]|[a-z*]+)/i,
33
insideEqu = {
44
'equation-command': {
55
pattern: funcPattern,
@@ -11,7 +11,7 @@
1111
'comment': /%.*/m,
1212
// the verbatim environment prints whitespace to the document
1313
'cdata': {
14-
pattern: /(\\begin\{((?:verbatim|lstlisting)\*?)\})([\s\S]*?)(?=\\end\{\2\})/,
14+
pattern: /(\\begin\{((?:verbatim|lstlisting)\*?)\})[\s\S]*?(?=\\end\{\2\})/,
1515
lookbehind: true
1616
},
1717
/*
@@ -20,12 +20,12 @@
2020
*/
2121
'equation': [
2222
{
23-
pattern: /\$(?:\\?[\s\S])*?\$|\\\((?:\\?[\s\S])*?\\\)|\\\[(?:\\?[\s\S])*?\\\]/,
23+
pattern: /\$(?:\\[\s\S]|[^\\$])*\$|\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]/,
2424
inside: insideEqu,
2525
alias: 'string'
2626
},
2727
{
28-
pattern: /(\\begin\{((?:equation|math|eqnarray|align|multline|gather)\*?)\})([\s\S]*?)(?=\\end\{\2\})/,
28+
pattern: /(\\begin\{((?:equation|math|eqnarray|align|multline|gather)\*?)\})[\s\S]*?(?=\\end\{\2\})/,
2929
lookbehind: true,
3030
inside: insideEqu,
3131
alias: 'string'

components/prism-latex.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)