Closed paulsohn closed 8 years ago
Thanks! Looking this over now!
Really makes me wish we had some unit tests!
Writing some unit tests that cover current behaviour, so we can ensure nothing will break here.
I'm excited about the patch for throwOnError
. I'm hoping we can get some of those fixes pushed upstream.
According to the new tests (adapted from markdown-it-math), this does fix #2, but it also breaks the following:
Display math self-closes at the end of document
.
$$
1+1 = 2
.
<span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn><mo>+</mo><mn>1</mn><mo>=</mo><mn>2</mn></mrow><annotation encoding="application/x-tex">1+1 = 2
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.72777em;vertical-align:-0.08333em;"></span><span class="base displaystyle textstyle uncramped"><span class="mord mathrm">1</span><span class="mbin">+</span><span class="mord mathrm">1</span><span class="mrel">=</span><span class="mord mathrm">2</span></span></span></span></span>
.
Going to look through the code and see if this is an easy fix.
Okay, I missed that test things. I had ignored the rules '4 indents are code block'[1] and 'opening $$ tag closes itself if there's no closing $$ tag in the end of any line after', just thinking those are no need to be here, I removed those.
Therefore, in this commit, changes of optimization and new logic of escaping inline $ sign would be valid.
[1] though I still can't understand why it is needed.
My inline escaping is based on following regular expression:
(?<!\\)(?:((?<!\$)\$(?!\$)))([^\n\r]+)(?<!\\)(?(1)(?<!\$)\1(?!\$))
If only javascript regexp interpreter has a lookbehind options.
Okay, I think I've got fixes for the broken stuff. Merging. :tada: