Skip to content

Commit

Permalink
FIXED: Fix issue with dollar math delimiters inside code (fixes #134)
Browse files Browse the repository at this point in the history
  • Loading branch information
fletcher committed Jul 17, 2018
1 parent 3003fef commit 13458b3
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
32 changes: 20 additions & 12 deletions Sources/libMultiMarkdown/html.c
Original file line number Diff line number Diff line change
Expand Up @@ -2144,21 +2144,11 @@ void mmd_export_token_html_raw(DString * out, const char * source, token * t, sc
break;

case MATH_DOLLAR_SINGLE:
if (t->mate) {
(t->start < t->mate->start) ? ( print_const("\\(") ) : ( print_const("\\)") );
} else {
print_const("$");
}

print_const("$");
break;

case MATH_DOLLAR_DOUBLE:
if (t->mate) {
(t->start < t->mate->start) ? ( print_const("\\[") ) : ( print_const("\\]") );
} else {
print_const("$$");
}

print_const("$$");
break;

case MATH_PAREN_OPEN:
Expand Down Expand Up @@ -2227,6 +2217,24 @@ void mmd_export_token_html_math(DString * out, const char * source, token * t, s
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;
Expand Down
8 changes: 8 additions & 0 deletions tests/MMD6Tests/Math.fodt
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ office:mimetype="application/vnd.oasis.opendocument.text">
<text:p text:style-name="Standard">25</text:p>

<text:p text:style-name="Standard"><text:span text:style-name="math">\[\pi~2\]</text:span></text:p>

<text:p text:style-name="Standard"><text:span text:style-name="Source_20_Text">$a*x*y$</text:span></text:p>

<text:p text:style-name="Standard"><text:span text:style-name="Source_20_Text">$$a*x*y$$</text:span></text:p>

<text:p text:style-name="Standard"><text:span text:style-name="Source_20_Text">\\(a*x*y\\)</text:span></text:p>

<text:p text:style-name="Standard"><text:span text:style-name="Source_20_Text">\\[a*x*y\\]</text:span></text:p>
</office:text>
</office:body>
</office:document>
8 changes: 8 additions & 0 deletions tests/MMD6Tests/Math.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@

<p><span class="math">\[\pi~2\]</span></p>

<p><code>$a*x*y$</code></p>

<p><code>$$a*x*y$$</code></p>

<p><code>\\(a*x*y\\)</code></p>

<p><code>\\[a*x*y\\]</code></p>

</body>
</html>

8 changes: 8 additions & 0 deletions tests/MMD6Tests/Math.htmlc
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ latex config: article</p>
<p>25</p>

<p>\[\pi~2\]</p>

<p><code>$a*x*y$</code></p>

<p><code>$$a*x*y$$</code></p>

<p><code>\\(a*x*y\\)</code></p>

<p><code>\\[a*x*y\\]</code></p>
8 changes: 8 additions & 0 deletions tests/MMD6Tests/Math.tex
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,13 @@

\[\pi~2\]

\texttt{\$a*x*y\$}

\texttt{\$\$a*x*y\$\$}

\texttt{\textbackslash{}\textbackslash{}(a*x*y\textbackslash{}\textbackslash{})}

\texttt{\textbackslash{}\textbackslash{}[a*x*y\textbackslash{}\textbackslash{}]}

\input{mmd6-article-footer}
\end{document}
8 changes: 8 additions & 0 deletions tests/MMD6Tests/Math.text
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ $a *foo* b$
25

\\[\pi~2\\]

`$a*x*y$`

`$$a*x*y$$`

`\\(a*x*y\\)`

`\\[a*x*y\\]`

0 comments on commit 13458b3

Please sign in to comment.