Skip to content

Commit

Permalink
fix regexp issue with brackets
Browse files Browse the repository at this point in the history
There are 2 regexps to match equations contained in brackets,

one is math_block_eqno, the other is math_block,

the first regexp matches equations with an index at the end,

aaaa (1)

the second regexp matches equations without an index

bbbb

the program prioritize the first regexp over the second,

but when multiple equations present with only some of them having

an index. Javascript regexp will greedly match the longest string

that fulfill the first regexp.

For example

bbbb
aaaa (1)

becomes one single equation, instead of 2.

The fix adds a negative lookahead to exclude \\\[ \\\] patterns
from a match.

fix goessner#9
  • Loading branch information
shi-yan committed Dec 31, 2018
1 parent bbfdc4a commit ad57726
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions texmath.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ texmath.block = (rule) =>
let token = state.push(rule.name, 'math', 0);
token.block = true;
token.content = res[1];
token.info = res[2];
token.info = res[res.length-1];
token.markup = rule.tag;
}
for (let line=begLine, endpos=res.lastIndex-1; line < endLine; line++)
Expand Down Expand Up @@ -153,12 +153,12 @@ texmath.rules = {
],
block: [
{ name: 'math_block_eqno',
rex: /\\\[([\s\S]+?)\\\]\s*?\(([^)$\r\n]+?)\)/gmy,
rex: /\\\[(((?!\\\]|\\\[)[\s\S])+?)\\\]\s*?\(([^)$\r\n]+?)\)/gmy,
tmpl: '<section class="eqno"><eqn>$1</eqn><span>($2)</span></section>',
tag: '\\['
},
{ name: 'math_block',
rex: /\\\[(.+?)\\\]/gmy,
rex: /\\\[([\s\S]+?)\\\]/gmy,
tmpl: '<section><eqn>$1</eqn></section>',
tag: '\\['
}
Expand Down

0 comments on commit ad57726

Please sign in to comment.