]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Don't parse MMD inside math (fixes #69)
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 28 May 2017 19:25:35 +0000 (15:25 -0400)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 28 May 2017 19:25:35 +0000 (15:25 -0400)
Sources/libMultiMarkdown/html.c
Sources/libMultiMarkdown/mmd.c
tests/MMD6Tests/Math.fodt
tests/MMD6Tests/Math.html
tests/MMD6Tests/Math.htmlc
tests/MMD6Tests/Math.tex
tests/MMD6Tests/Math.text

index ce531d69d1e280c6e82cf4de21a7a2d4150bfa83..f33ee8f97f52158ec5955fd4669bbd7a575d1076 100644 (file)
@@ -1508,8 +1508,12 @@ void mmd_export_token_html(DString * out, const char * source, token * t, scratc
                case PAIR_HTML_COMMENT:
                        print_token(t);
                        break;
-               case PAIR_EMPH:
                case PAIR_MATH:
+                       print_const("<span class=\"math\">");
+                       mmd_export_token_tree_html_raw(out, source, t->child, scratch);
+                       print_const("</span>");
+                       break;
+               case PAIR_EMPH:
                case PAIR_PAREN:
                case PAIR_QUOTE_DOUBLE:
                case PAIR_QUOTE_SINGLE:
@@ -1711,6 +1715,32 @@ void mmd_export_token_html_raw(DString * out, const char * source, token * t, sc
                        print_const("\\");
                        mmd_print_char_html(out, source[t->start + 1], false);
                        break;
+               case MATH_BRACKET_OPEN:
+                       print_const("\\[");
+                       break;
+               case MATH_BRACKET_CLOSE:
+                       print_const("\\]");
+                       break;
+               case MATH_DOLLAR_SINGLE:
+                       if (t->mate) {
+                               (t->start < t->mate->start) ? ( print_const("\\(") ) : ( print_const("\\)") );
+                       } else {
+                               print_const("$");
+                       }
+                       break;
+               case MATH_DOLLAR_DOUBLE:
+                       if (t->mate) {
+                               (t->start < t->mate->start) ? ( print_const("\\[") ) : ( print_const("\\]") );
+                       } else {
+                               print_const("$$");
+                       }
+                       break;
+               case MATH_PAREN_OPEN:
+                       print_const("\\(");
+                       break;
+               case MATH_PAREN_CLOSE:
+                       print_const("\\)");
+                       break;
                case QUOTE_DOUBLE:
                        print_const("&quot;");
                        break;
index bcdca83cc79277315a8335214722ece3952318db..d9d59bb812c164707367cb0f29703218a22cdb74 100644 (file)
@@ -1460,8 +1460,16 @@ void pair_emphasis_tokens(token * t) {
 
                }
                
-               if (t->child != NULL)
-                       pair_emphasis_tokens(t->child);
+               if (t->child != NULL) {
+                       switch(t->type) {
+                               case PAIR_BACKTICK:
+                               case PAIR_MATH:
+                                       break;
+                               default:
+                                       pair_emphasis_tokens(t->child);
+                                       break;
+                       }
+               }
                
                t = t->next;
        }
index 2b24ea83e34029ed8d217181d745dee4130fe80a..e6d74cf8d09e4512c5ff8ae6ba3f11ffe7e3ef70 100644 (file)
 <text:p text:style-name="Standard"><text:span text:style-name="math">\[\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}\]</text:span></text:p>
 
 <text:p text:style-name="Standard"><text:span text:style-name="Source_20_Text">\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}</text:span></text:p>
+
+<text:p text:style-name="Standard"><text:span text:style-name="math">\(a *foo* b\)</text:span></text:p>
+
+<text:p text:style-name="Standard"><text:span text:style-name="math">\[a *foo* b\]</text:span></text:p>
 </office:text>
 </office:body>
 </office:document>
index 1408abf2cf79ffbaebd371b4dfd180f18ce3a5a7..b12f0a3eb7465690118f797bd9b06e8b7fbebb6d 100644 (file)
 
 <p><code>\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}</code></p>
 
+<p><span class="math">\(a *foo* b\)</span></p>
+
+<p><span class="math">\[a *foo* b\]</span></p>
+
 </body>
 </html>
 
index 3b235bf961b9b184f8a779021a8b19930d642d35..e85b5dd1ffb4e0038b7027c7ec8331aa2ce2138f 100644 (file)
@@ -52,3 +52,7 @@ latex config: article</p>
 <p>\[\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}\]</p>
 
 <p><code>\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}</code></p>
+
+<p>$a <em>foo</em> b$</p>
+
+<p>\[a <em>foo</em> b\]</p>
index c4d99df26c1488396edc08c76910d51794f0de4a..1c700292641df1cad6c55b11bb2fd1264cc57090 100644 (file)
@@ -54,5 +54,9 @@ $$\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}$$
 
 \texttt{\textbackslash{}begin\{equation\}\textbackslash{}nabla \textbackslash{}times \textbackslash{}mathbf\{E\} = - \textbackslash{}frac\{\textbackslash{}partial \textbackslash{}mathbf\{B\}\}\{\textbackslash{}partial t\}\textbackslash{}end\{equation\}}
 
+$a *foo* b$
+
+\[a *foo* b\]
+
 \input{mmd6-article-footer}
 \end{document}
index e5f5c8668685bd8a028464c97e3dac014a404e1c..a618607b7a104dff24bb06cfe257ece5a0362fac 100644 (file)
@@ -52,3 +52,7 @@ $$\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\parti
 \\[\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}\\]
 
 `\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}`
+
+$a *foo* b$
+
+\\[a *foo* b\\]