From d6e8d2f7b49427c59a952401a1ab95f1e02c5637 Mon Sep 17 00:00:00 2001 From: "Fletcher T. Penney" Date: Sun, 12 Feb 2017 19:19:22 -0500 Subject: [PATCH] FIXED: Separate LaTeX verbatim and texttt character handling --- src/latex.c | 47 ++++++++++++++++++---- src/latex.h | 3 ++ tests/MMD6Tests/Amps and Angles.tex | 8 ++-- tests/MMD6Tests/Automatic Links.tex | 2 +- tests/MMD6Tests/Horizontal Rules.tex | 2 +- tests/MMD6Tests/Indented Code Blocks.html | 5 +++ tests/MMD6Tests/Indented Code Blocks.htmlc | 5 +++ tests/MMD6Tests/Indented Code Blocks.tex | 6 +++ tests/MMD6Tests/Indented Code Blocks.text | 4 ++ tests/MMD6Tests/Integrated.html | 10 ++++- tests/MMD6Tests/Integrated.htmlc | 10 ++++- tests/MMD6Tests/Integrated.tex | 10 ++++- tests/MMD6Tests/Integrated.text | 10 ++++- 13 files changed, 105 insertions(+), 17 deletions(-) diff --git a/src/latex.c b/src/latex.c index 67c9b94..7c13adc 100644 --- a/src/latex.c +++ b/src/latex.c @@ -742,7 +742,7 @@ void mmd_export_token_latex(DString * out, const char * source, token * t, scrat t->child->type = TEXT_EMPTY; t->child->mate->type = TEXT_EMPTY; print("\\texttt{"); - mmd_export_token_tree_latex_raw(out, source, t->child, scratch); + mmd_export_token_tree_latex_tt(out, source, t->child, scratch); print("}"); break; case PAIR_BRACES: @@ -1126,13 +1126,46 @@ void mmd_export_token_latex_raw(DString * out, const char * source, token * t, s if (t == NULL) return; + switch (t->type) { + case ESCAPED_CHARACTER: + mmd_print_char_latex(out, source[t->start + 1]); + break; + case CODE_FENCE: + if (t->next) + t->next->type = TEXT_EMPTY; + case TEXT_EMPTY: + break; + default: + if (t->child) + mmd_export_token_tree_latex_raw(out, source, t->child, scratch); + else + print_token(t); + break; + } +} + + +void mmd_export_token_tree_latex_raw(DString * out, const char * source, token * t, scratch_pad * scratch) { + while (t != NULL) { + if (scratch->skip_token) { + scratch->skip_token--; + } else { + mmd_export_token_latex_raw(out, source, t, scratch); + } + + t = t->next; + } +} + + +void mmd_export_token_latex_tt(DString * out, const char * source, token * t, scratch_pad * scratch) { + if (t == NULL) + return; + switch (t->type) { case AMPERSAND: print("\\&"); break; - case AMPERSAND_LONG: - print("\\textbackslash{}&"); - break; case ANGLE_LEFT: print("$<$"); break; @@ -1160,7 +1193,7 @@ void mmd_export_token_latex_raw(DString * out, const char * source, token * t, s break; default: if (t->child) - mmd_export_token_tree_latex_raw(out, source, t->child, scratch); + mmd_export_token_tree_latex_tt(out, source, t->child, scratch); else print_token(t); break; @@ -1168,12 +1201,12 @@ void mmd_export_token_latex_raw(DString * out, const char * source, token * t, s } -void mmd_export_token_tree_latex_raw(DString * out, const char * source, token * t, scratch_pad * scratch) { +void mmd_export_token_tree_latex_tt(DString * out, const char * source, token * t, scratch_pad * scratch) { while (t != NULL) { if (scratch->skip_token) { scratch->skip_token--; } else { - mmd_export_token_latex_raw(out, source, t, scratch); + mmd_export_token_latex_tt(out, source, t, scratch); } t = t->next; diff --git a/src/latex.h b/src/latex.h index ed2d38c..0734a15 100644 --- a/src/latex.h +++ b/src/latex.h @@ -68,6 +68,9 @@ void mmd_export_token_tree_latex(DString * out, const char * source, token * t, void mmd_export_token_latex_raw(DString * out, const char * source, token * t, scratch_pad * scratch); void mmd_export_token_tree_latex_raw(DString * out, const char * source, token * t, scratch_pad * scratch); +void mmd_export_token_latex_tt(DString * out, const char * source, token * t, scratch_pad * scratch); +void mmd_export_token_tree_latex_tt(DString * out, const char * source, token * t, scratch_pad * scratch); + void mmd_export_citation_list_latex(DString * out, const char * source, scratch_pad * scratch); void mmd_export_footnote_list_latex(DString * out, const char * source, scratch_pad * scratch); diff --git a/tests/MMD6Tests/Amps and Angles.tex b/tests/MMD6Tests/Amps and Angles.tex index 0ace92d..860d6af 100644 --- a/tests/MMD6Tests/Amps and Angles.tex +++ b/tests/MMD6Tests/Amps and Angles.tex @@ -10,13 +10,13 @@ This \& that. 5 -Here is a \href{http://example.com/?foo=1&bar=2}{link}\footnote{\href{http://example.com/?foo=1\&bar=2}{http:/\slash example.com\slash ?foo=1\&bar=2}} with an ampersand in the URL. +Here is a \href{http://example.com/?foo=1&bar=2}{link}\footnote{\href{http://example.com/?foo=1&bar=2}{http:\slash \slash example.com\slash ?foo=1\&bar=2}} with an ampersand in the URL. -Here is a link with an amersand in the link text: \href{http://att.com/}{AT\&T}\footnote{\href{http://att.com/}{http:/\slash att.com\slash }}. +Here is a link with an amersand in the link text: \href{http://att.com/}{AT\&T}\footnote{\href{http://att.com/}{http:\slash \slash att.com\slash }}. -Here is an inline \href{/script?foo=1&bar=2}{link}\footnote{\href{/script?foo=1\&bar=2}{\slash script?foo=1\&bar=2}}. +Here is an inline \href{/script?foo=1&bar=2}{link}\footnote{\href{/script?foo=1&bar=2}{\slash script?foo=1\&bar=2}}. -Here is an inline \href{/script?foo=1&bar=2}{link}\footnote{\href{/script?foo=1\&bar=2}{\slash script?foo=1\&bar=2}}. +Here is an inline \href{/script?foo=1&bar=2}{link}\footnote{\href{/script?foo=1&bar=2}{\slash script?foo=1\&bar=2}}. \begin{verbatim} & and & and < and > in code block. diff --git a/tests/MMD6Tests/Automatic Links.tex b/tests/MMD6Tests/Automatic Links.tex index b587ee8..d863de3 100644 --- a/tests/MMD6Tests/Automatic Links.tex +++ b/tests/MMD6Tests/Automatic Links.tex @@ -1,3 +1,3 @@ -\href{http://foo.com/}{http:/\slash foo.com\slash } +\href{http://foo.com/}{http:\slash \slash foo.com\slash } \href{mailto:foo@bar.com}{foo@bar.com} diff --git a/tests/MMD6Tests/Horizontal Rules.tex b/tests/MMD6Tests/Horizontal Rules.tex index e52e1a6..89ce0e9 100644 --- a/tests/MMD6Tests/Horizontal Rules.tex +++ b/tests/MMD6Tests/Horizontal Rules.tex @@ -9,7 +9,7 @@ Dashes: \begin{center}\rule{3in}{0.4pt}\end{center} \begin{verbatim} --{}-{}- +--- \end{verbatim} 5 diff --git a/tests/MMD6Tests/Indented Code Blocks.html b/tests/MMD6Tests/Indented Code Blocks.html index d170468..90fb69a 100644 --- a/tests/MMD6Tests/Indented Code Blocks.html +++ b/tests/MMD6Tests/Indented Code Blocks.html @@ -56,3 +56,8 @@ bar bar + +

foo

+ +
-<>--&\&---...
+
diff --git a/tests/MMD6Tests/Indented Code Blocks.htmlc b/tests/MMD6Tests/Indented Code Blocks.htmlc index d170468..90fb69a 100644 --- a/tests/MMD6Tests/Indented Code Blocks.htmlc +++ b/tests/MMD6Tests/Indented Code Blocks.htmlc @@ -56,3 +56,8 @@ bar bar + +

foo

+ +
-<>--&\&---...
+
diff --git a/tests/MMD6Tests/Indented Code Blocks.tex b/tests/MMD6Tests/Indented Code Blocks.tex index 90e6964..8f5ee2b 100644 --- a/tests/MMD6Tests/Indented Code Blocks.tex +++ b/tests/MMD6Tests/Indented Code Blocks.tex @@ -64,3 +64,9 @@ bar bar \end{verbatim} + +foo + +\begin{verbatim} +-<>--&\&---... +\end{verbatim} diff --git a/tests/MMD6Tests/Indented Code Blocks.text b/tests/MMD6Tests/Indented Code Blocks.text index 4256b80..f72815e 100644 --- a/tests/MMD6Tests/Indented Code Blocks.text +++ b/tests/MMD6Tests/Indented Code Blocks.text @@ -48,3 +48,7 @@ foo bar bar + +foo + + -<>--&\&---... diff --git a/tests/MMD6Tests/Integrated.html b/tests/MMD6Tests/Integrated.html index 30885d4..70814ce 100644 --- a/tests/MMD6Tests/Integrated.html +++ b/tests/MMD6Tests/Integrated.html @@ -65,7 +65,15 @@ code

Math

-

math \({e}^{i\pi }+1=0\)

+

foo \({e}^{i\pi }+1=0\) bar

+ +

\[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \]

+ +

foo \({e}^{i\pi }+1=0\) bar

+ +

foo \({e}^{i\pi }+1=0\), bar

+ +

\[{x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}\]

Smart Quotes

diff --git a/tests/MMD6Tests/Integrated.htmlc b/tests/MMD6Tests/Integrated.htmlc index b9477cf..0bb4899 100644 --- a/tests/MMD6Tests/Integrated.htmlc +++ b/tests/MMD6Tests/Integrated.htmlc @@ -65,7 +65,15 @@ code

Math

-

math ${e}^{i\pi }+1=0$

+

foo \({e}^{i\pi }+1=0\) bar

+ +

\[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \]

+ +

foo ${e}^{i\pi }+1=0$ bar

+ +

foo ${e}^{i\pi }+1=0$, bar

+ +

$${x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}$$

Smart Quotes

diff --git a/tests/MMD6Tests/Integrated.tex b/tests/MMD6Tests/Integrated.tex index e088faf..26e7074 100644 --- a/tests/MMD6Tests/Integrated.tex +++ b/tests/MMD6Tests/Integrated.tex @@ -78,7 +78,15 @@ foo (\autoref{math}) \part{Math } \label{math} -math ${e}^{i\pi }+1=0$ +foo \({e}^{i\pi }+1=0\) bar + +\[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \] + +foo ${e}^{i\pi }+1=0$ bar + +foo ${e}^{i\pi }+1=0$, bar + +$${x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}$$ \part{Smart Quotes } \label{smartquotes} diff --git a/tests/MMD6Tests/Integrated.text b/tests/MMD6Tests/Integrated.text index 744aa3f..6f90471 100644 --- a/tests/MMD6Tests/Integrated.text +++ b/tests/MMD6Tests/Integrated.text @@ -70,7 +70,15 @@ Cite.[#Inline Citation] # Math # -math ${e}^{i\pi }+1=0$ +foo \\({e}^{i\pi }+1=0\\) bar + +\\[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \\] + +foo ${e}^{i\pi }+1=0$ bar + +foo ${e}^{i\pi }+1=0$, bar + +$${x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}$$ # Smart Quotes # -- 2.40.0