waylonflinn / markdown-it-katex

Add Math to your Markdown with a KaTeX plugin for Markdown-it
MIT License
252 stars 155 forks source link

Fixed index.js delimeter logic #3

Closed paulsohn closed 8 years ago

paulsohn commented 8 years ago
waylonflinn commented 8 years ago

Thanks! Looking this over now!

Really makes me wish we had some unit tests!

waylonflinn commented 8 years ago

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.

waylonflinn commented 8 years ago

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.

paulsohn commented 8 years ago

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.

paulsohn commented 8 years ago

My inline escaping is based on following regular expression: (?<!\\)(?:((?<!\$)\$(?!\$)))([^\n\r]+)(?<!\\)(?(1)(?<!\$)\1(?!\$))

If only javascript regexp interpreter has a lookbehind options.

waylonflinn commented 8 years ago

Okay, I think I've got fixes for the broken stuff. Merging. :tada: