From cb08ff2d9952d807eb79897585fc6dc44e473ca4 Mon Sep 17 00:00:00 2001 From: "Fletcher T. Penney" Date: Sun, 28 May 2017 15:25:35 -0400 Subject: [PATCH] FIXED: Don't parse MMD inside math (fixes #69) --- Sources/libMultiMarkdown/html.c | 32 +++++++++++++++++++++++++++++++- Sources/libMultiMarkdown/mmd.c | 12 ++++++++++-- tests/MMD6Tests/Math.fodt | 4 ++++ tests/MMD6Tests/Math.html | 4 ++++ tests/MMD6Tests/Math.htmlc | 4 ++++ tests/MMD6Tests/Math.tex | 4 ++++ tests/MMD6Tests/Math.text | 4 ++++ 7 files changed, 61 insertions(+), 3 deletions(-) diff --git a/Sources/libMultiMarkdown/html.c b/Sources/libMultiMarkdown/html.c index ce531d6..f33ee8f 100644 --- a/Sources/libMultiMarkdown/html.c +++ b/Sources/libMultiMarkdown/html.c @@ -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(""); + mmd_export_token_tree_html_raw(out, source, t->child, scratch); + print_const(""); + 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("""); break; diff --git a/Sources/libMultiMarkdown/mmd.c b/Sources/libMultiMarkdown/mmd.c index bcdca83..d9d59bb 100644 --- a/Sources/libMultiMarkdown/mmd.c +++ b/Sources/libMultiMarkdown/mmd.c @@ -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; } diff --git a/tests/MMD6Tests/Math.fodt b/tests/MMD6Tests/Math.fodt index 2b24ea8..e6d74cf 100644 --- a/tests/MMD6Tests/Math.fodt +++ b/tests/MMD6Tests/Math.fodt @@ -327,6 +327,10 @@ \[\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\] diff --git a/tests/MMD6Tests/Math.html b/tests/MMD6Tests/Math.html index 1408abf..b12f0a3 100644 --- a/tests/MMD6Tests/Math.html +++ b/tests/MMD6Tests/Math.html @@ -58,6 +58,10 @@

\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}

+

\(a *foo* b\)

+ +

\[a *foo* b\]

+ diff --git a/tests/MMD6Tests/Math.htmlc b/tests/MMD6Tests/Math.htmlc index 3b235bf..e85b5dd 100644 --- a/tests/MMD6Tests/Math.htmlc +++ b/tests/MMD6Tests/Math.htmlc @@ -52,3 +52,7 @@ latex config: article

\[\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\]

diff --git a/tests/MMD6Tests/Math.tex b/tests/MMD6Tests/Math.tex index c4d99df..1c70029 100644 --- a/tests/MMD6Tests/Math.tex +++ b/tests/MMD6Tests/Math.tex @@ -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} diff --git a/tests/MMD6Tests/Math.text b/tests/MMD6Tests/Math.text index e5f5c86..a618607 100644 --- a/tests/MMD6Tests/Math.text +++ b/tests/MMD6Tests/Math.text @@ -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\\] -- 2.40.0