From: Fletcher T. Penney Date: Sun, 28 May 2017 17:47:14 +0000 (-0400) Subject: FIXED: Refactor super/subscript parsing (fixes #70) X-Git-Tag: 6.1.0^2~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aae26a8959ad9db628866703b35815ba0affc296;p=multimarkdown FIXED: Refactor super/subscript parsing (fixes #70) --- diff --git a/Sources/libMultiMarkdown/mmd.c b/Sources/libMultiMarkdown/mmd.c index 6bf559a..bcdca83 100644 --- a/Sources/libMultiMarkdown/mmd.c +++ b/Sources/libMultiMarkdown/mmd.c @@ -1353,19 +1353,37 @@ void mmd_assign_ambidextrous_tokens_in_block(mmd_engine * e, token * block, size t->can_open = 0; } + // We need to be contiguous in order to match + if (t->can_close) { + offset = t->start; + t->can_close = 0; + + while ((offset > 0) && !(char_is_whitespace_or_line_ending(str[offset - 1]))) { + if (str[offset - 1] == str[t->start]) { + t->can_close = 1; + break; + } + + offset--; + } + } + // We need to be contiguous in order to match if (t->can_open) { offset = t->start + t->len; t->can_open = 0; while (!(char_is_whitespace_or_line_ending(str[offset]))) { - if (str[offset] == str[t->start]) + if (str[offset] == str[t->start]) { t->can_open = 1; + break; + } + offset++; } // Are we a standalone, e.g x^2 - if (!t->can_open) { + if (!t->can_close && !t->can_open) { offset = t->start + t->len; while (!char_is_whitespace_or_line_ending_or_punctuation(str[offset])) offset++; @@ -1388,17 +1406,6 @@ void mmd_assign_ambidextrous_tokens_in_block(mmd_engine * e, token * block, size } } - // We need to be contiguous in order to match - if (t->can_close) { - offset = t->start; - t->can_close = 0; - - while ((offset > 0) && !(char_is_whitespace_or_line_ending(str[offset - 1]))) { - if (str[offset - 1] == str[t->start]) - t->can_close = 1; - offset--; - } - } break; } diff --git a/tests/MMD6Tests/Superscript.fodt b/tests/MMD6Tests/Superscript.fodt index a5796e7..968c464 100644 --- a/tests/MMD6Tests/Superscript.fodt +++ b/tests/MMD6Tests/Superscript.fodt @@ -307,6 +307,14 @@ x2 3~ x2 32 + +H2O + +15 + +CH3CH2CH2CH3 + +CH3CH2CH2CH~3 diff --git a/tests/MMD6Tests/Superscript.html b/tests/MMD6Tests/Superscript.html index 92f0309..959ba48 100644 --- a/tests/MMD6Tests/Superscript.html +++ b/tests/MMD6Tests/Superscript.html @@ -38,6 +38,14 @@

x2 32

+

H2O

+ +

15

+ +

CH3CH2CH2CH3

+ +

CH3CH2CH2CH~3

+ diff --git a/tests/MMD6Tests/Superscript.htmlc b/tests/MMD6Tests/Superscript.htmlc index 4478948..051321c 100644 --- a/tests/MMD6Tests/Superscript.htmlc +++ b/tests/MMD6Tests/Superscript.htmlc @@ -32,3 +32,11 @@ latex config: article

x~2 3~

x~2 3~2

+ +

H~2~O

+ +

15

+ +

CH~3~CH~2~CH~2~CH~3~

+ +

CH~3~CH~2~CH~2~CH~3

diff --git a/tests/MMD6Tests/Superscript.tex b/tests/MMD6Tests/Superscript.tex index a8930dc..28ec3c9 100644 --- a/tests/MMD6Tests/Superscript.tex +++ b/tests/MMD6Tests/Superscript.tex @@ -34,5 +34,13 @@ x\textsubscript{2} 3\ensuremath{\sim} x\textsubscript{2} 3\textsubscript{2} +H\textsubscript{2}O + +15 + +CH\textsubscript{3}CH\textsubscript{2}CH\textsubscript{2}CH\textsubscript{3} + +CH\textsubscript{3}CH\textsubscript{2}CH\textsubscript{2}CH\ensuremath{\sim}3 + \input{mmd6-article-footer} \end{document} diff --git a/tests/MMD6Tests/Superscript.text b/tests/MMD6Tests/Superscript.text index 965cdb0..8c5c7bd 100644 --- a/tests/MMD6Tests/Superscript.text +++ b/tests/MMD6Tests/Superscript.text @@ -32,3 +32,11 @@ x\~y x~2 3~ x~2 3~2 + +H~2~O + +15 + +CH~3~CH~2~CH~2~CH~3~ + +CH~3~CH~2~CH~2~CH~3 \ No newline at end of file