]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Fix math markers in code spans
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Thu, 12 Oct 2017 18:39:03 +0000 (14:39 -0400)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Thu, 12 Oct 2017 18:39:03 +0000 (14:39 -0400)
Sources/libMultiMarkdown/html.c
Sources/libMultiMarkdown/html.h
Sources/libMultiMarkdown/latex.c
tests/MMD6Tests/Escapes.fodt
tests/MMD6Tests/Escapes.html
tests/MMD6Tests/Escapes.htmlc
tests/MMD6Tests/Escapes.tex
tests/MMD6Tests/Escapes.text

index 156f333f24a90fbea00a99922b810c7b0cf46072..c2549d30847e940ba17ae63610b202de28b51149 100644 (file)
@@ -1816,7 +1816,7 @@ parse_citation:
 
                case PAIR_MATH:
                        print_const("<span class=\"math\">");
-                       mmd_export_token_tree_html_raw(out, source, t->child, scratch);
+                       mmd_export_token_tree_html_math(out, source, t->child, scratch);
                        print_const("</span>");
                        break;
 
@@ -2076,11 +2076,11 @@ void mmd_export_token_html_raw(DString * out, const char * source, token * t, sc
                        break;
 
                case MATH_BRACKET_OPEN:
-                       print_const("\\[");
+                       print_const("\\\\[");
                        break;
 
                case MATH_BRACKET_CLOSE:
-                       print_const("\\]");
+                       print_const("\\\\]");
                        break;
 
                case MATH_DOLLAR_SINGLE:
@@ -2102,11 +2102,11 @@ void mmd_export_token_html_raw(DString * out, const char * source, token * t, sc
                        break;
 
                case MATH_PAREN_OPEN:
-                       print_const("\\(");
+                       print_const("\\\\(");
                        break;
 
                case MATH_PAREN_CLOSE:
-                       print_const("\\)");
+                       print_const("\\\\)");
                        break;
 
                case QUOTE_DOUBLE:
@@ -2133,6 +2133,35 @@ void mmd_export_token_html_raw(DString * out, const char * source, token * t, sc
 }
 
 
+void mmd_export_token_html_math(DString * out, const char * source, token * t, scratch_pad * scratch) {
+       if (t == NULL) {
+               return;
+       }
+
+       switch (t->type) {
+               case MATH_BRACKET_OPEN:
+                       print_const("\\[");
+                       break;
+
+               case MATH_BRACKET_CLOSE:
+                       print_const("\\]");
+                       break;
+
+               case MATH_PAREN_OPEN:
+                       print_const("\\(");
+                       break;
+
+               case MATH_PAREN_CLOSE:
+                       print_const("\\)");
+                       break;
+
+               default:
+                       mmd_export_token_html_raw(out, source, t, scratch);
+                       break;
+       }
+}
+
+
 void mmd_start_complete_html(DString * out, const char * source, scratch_pad * scratch) {
        meta * m;
 
@@ -2246,6 +2275,19 @@ void mmd_export_token_tree_html_raw(DString * out, const char * source, token *
 }
 
 
+void mmd_export_token_tree_html_math(DString * out, const char * source, token * t, scratch_pad * scratch) {
+       while (t != NULL) {
+               if (scratch->skip_token) {
+                       scratch->skip_token--;
+               } else {
+                       mmd_export_token_html_math(out, source, t, scratch);
+               }
+
+               t = t->next;
+       }
+}
+
+
 void mmd_export_footnote_list_html(DString * out, const char * source, scratch_pad * scratch) {
        if (scratch->used_footnotes->size > 0) {
                footnote * note;
index 39a4b7457d070d1116bdba235d65f401c7fb0867..26386bf71ed16ca6929d40826666a9c589838785 100644 (file)
@@ -66,6 +66,7 @@ void mmd_export_token_tree_html(DString * out, const char * source, token * t, s
 
 void mmd_export_token_html_raw(DString * out, const char * source, token * t, scratch_pad * scratch);
 void mmd_export_token_tree_html_raw(DString * out, const char * source, token * t, scratch_pad * scratch);
+void mmd_export_token_tree_html_math(DString * out, const char * source, token * t, scratch_pad * scratch);
 
 void mmd_export_citation_list_html(DString * out, const char * source, scratch_pad * scratch);
 void mmd_export_footnote_list_html(DString * out, const char * source, scratch_pad * scratch);
index 6b31942b35fb83ec553747e049958da299ab0089..389f686021d9c261d1e780c6695db3d0f04ed083 100644 (file)
@@ -2132,6 +2132,14 @@ void mmd_export_token_latex_tt(DString * out, const char * source, token * t, sc
                                t->next->type = TEXT_EMPTY;
                        }
 
+               case MATH_BRACKET_OPEN:
+               case MATH_BRACKET_CLOSE:
+               case MATH_PAREN_OPEN:
+               case MATH_PAREN_CLOSE:
+                       print_const("\\textbackslash{}\\textbackslash{}");
+                       print_char(source[t->start + 2]);
+                       break;
+
                case TEXT_EMPTY:
                        break;
 
index 031e3c4dbd4fd96b434f32dbbd212765053bd8ec..1f74fb98da5db06397c86f54718810ee453b5c84 100644 (file)
@@ -367,6 +367,8 @@ office:mimetype="application/vnd.oasis.opendocument.text">
 <text:p text:style-name="Standard">`foo`</text:p>
 
 <text:p text:style-name="Standard">foo bar</text:p>
+
+<text:p text:style-name="Standard"><text:span text:style-name="Source_20_Text">\\[foo]</text:span></text:p>
 </office:text>
 </office:body>
 </office:document>
index 6c6d413827988fe801623f5c927409791bc64a69..562ce779879c26742812380e489378c99e22580a 100644 (file)
 
 <p>foo&nbsp;bar</p>
 
+<p><code>\\[foo]</code></p>
+
 </body>
 </html>
 
index 8a55c6f5103714880b82b1241f3afd773be7b68b..313e2571ae7201c4c0081cc7924f55530ea64424 100644 (file)
@@ -95,3 +95,5 @@ latex config: article</p>
 <p>`foo`</p>
 
 <p>foo bar</p>
+
+<p><code>\\[foo]</code></p>
index c54321ef3c0669e01960eecd0769724b78b49f0a..fc3cb3e9239547e99bdf4b14da12510d2c506e2c 100644 (file)
@@ -98,5 +98,7 @@ $>$
 
 foo~bar
 
+\texttt{\textbackslash{}\textbackslash{}[foo]}
+
 \input{mmd6-article-footer}
 \end{document}
index a5c49cf375d9c95b7985c3702d976036f88d1a9a..1d5562925d909bfee599ab1d0191a507e7d7b5e8 100644 (file)
@@ -94,3 +94,5 @@ latex config: article
 \`foo\`
 
 foo\ bar
+
+`\\[foo]`