]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Refactor super/subscript parsing (fixes #70)
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 28 May 2017 17:47:14 +0000 (13:47 -0400)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 28 May 2017 17:47:14 +0000 (13:47 -0400)
Sources/libMultiMarkdown/mmd.c
tests/MMD6Tests/Superscript.fodt
tests/MMD6Tests/Superscript.html
tests/MMD6Tests/Superscript.htmlc
tests/MMD6Tests/Superscript.tex
tests/MMD6Tests/Superscript.text

index 6bf559aba8c6c6c6190661a29d3c0fa5ebe92072..bcdca83cc79277315a8335214722ece3952318db 100644 (file)
@@ -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;
                }
                
index a5796e7e9da7875ea54530a218a350694852a27f..968c464a208138f24972d27810cefd23af883a0d 100644 (file)
 <text:p text:style-name="Standard">x<text:span text:style-name="MMD-Subscript">2</text:span> 3~</text:p>
 
 <text:p text:style-name="Standard">x<text:span text:style-name="MMD-Subscript">2</text:span> 3<text:span text:style-name="MMD-Subscript">2</text:span></text:p>
+
+<text:p text:style-name="Standard">H<text:span text:style-name="MMD-Subscript">2</text:span>O</text:p>
+
+<text:p text:style-name="Standard">15</text:p>
+
+<text:p text:style-name="Standard">CH<text:span text:style-name="MMD-Subscript">3</text:span>CH<text:span text:style-name="MMD-Subscript">2</text:span>CH<text:span text:style-name="MMD-Subscript">2</text:span>CH<text:span text:style-name="MMD-Subscript">3</text:span></text:p>
+
+<text:p text:style-name="Standard">CH<text:span text:style-name="MMD-Subscript">3</text:span>CH<text:span text:style-name="MMD-Subscript">2</text:span>CH<text:span text:style-name="MMD-Subscript">2</text:span>CH~3</text:p>
 </office:text>
 </office:body>
 </office:document>
index 92f03095f993f839c18add7762bc5ac51c67a86c..959ba48f17d06e260426d9255d81755444505a2f 100644 (file)
 
 <p>x<sub>2</sub> 3<sub>2</sub></p>
 
+<p>H<sub>2</sub>O</p>
+
+<p>15</p>
+
+<p>CH<sub>3</sub>CH<sub>2</sub>CH<sub>2</sub>CH<sub>3</sub></p>
+
+<p>CH<sub>3</sub>CH<sub>2</sub>CH<sub>2</sub>CH~3</p>
+
 </body>
 </html>
 
index 44789486efc7ce9883e7d7a96a6fad4f185c9379..051321c03d62713fe0aeeaea214f37bd1393324c 100644 (file)
@@ -32,3 +32,11 @@ latex config:        article</p>
 <p>x~2 3~</p>
 
 <p>x~2 3~2</p>
+
+<p>H~2~O</p>
+
+<p>15</p>
+
+<p>CH~3~CH~2~CH~2~CH~3~</p>
+
+<p>CH~3~CH~2~CH~2~CH~3</p>
index a8930dc918b393ff36a2e311b66dc6d259660de9..28ec3c9743cf1804044972a580b3d71962129f35 100644 (file)
@@ -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}
index 965cdb0ae32c37bf5efced87a6ed647f86e0026b..8c5c7bd712288b283bebdb8464f259cc2497249f 100644 (file)
@@ -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