]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Separate LaTeX verbatim and texttt character handling
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Mon, 13 Feb 2017 00:19:22 +0000 (19:19 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Mon, 13 Feb 2017 00:19:22 +0000 (19:19 -0500)
13 files changed:
src/latex.c
src/latex.h
tests/MMD6Tests/Amps and Angles.tex
tests/MMD6Tests/Automatic Links.tex
tests/MMD6Tests/Horizontal Rules.tex
tests/MMD6Tests/Indented Code Blocks.html
tests/MMD6Tests/Indented Code Blocks.htmlc
tests/MMD6Tests/Indented Code Blocks.tex
tests/MMD6Tests/Indented Code Blocks.text
tests/MMD6Tests/Integrated.html
tests/MMD6Tests/Integrated.htmlc
tests/MMD6Tests/Integrated.tex
tests/MMD6Tests/Integrated.text

index 67c9b94fcc9eeef415688eac7ed7a2a3353027e0..7c13adc6309fd0b42066a322aec14de513e4b81e 100644 (file)
@@ -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;
index ed2d38ce8c865de58e38baaa05d7d7c76e73a886..0734a15b6735f4590a4f6ae5580a9db16e4500fd 100644 (file)
@@ -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);
 
index 0ace92dc749d947a9b8da31b2458d824e360b79f..860d6af35c3c67f363d558e551314bf135b69ae9 100644 (file)
@@ -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 &amp; and < and > in code block.
index b587ee85ce7fb9fcd89318409b1fa812d1339302..d863de30bd1894fd524da64fd1bee3ee892f4056 100644 (file)
@@ -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}
index e52e1a668c6daa9b7c44bdaaf069d3c4e4c37b4c..89ce0e92a6397dae5f99c1edc7e9943213891e80 100644 (file)
@@ -9,7 +9,7 @@ Dashes:
 \begin{center}\rule{3in}{0.4pt}\end{center}
 
 \begin{verbatim}
--{}-{}-
+---
 \end{verbatim}
 
 5
index d17046880412752ee0213f51ef09cee7bdfd04af..90fb69ac649791546c25407c88af8c6a14ac316b 100644 (file)
@@ -56,3 +56,8 @@ bar
 
 bar
 </code></pre>
+
+<p>foo</p>
+
+<pre><code>-&lt;&gt;--&amp;\&amp;---...
+</code></pre>
index d17046880412752ee0213f51ef09cee7bdfd04af..90fb69ac649791546c25407c88af8c6a14ac316b 100644 (file)
@@ -56,3 +56,8 @@ bar
 
 bar
 </code></pre>
+
+<p>foo</p>
+
+<pre><code>-&lt;&gt;--&amp;\&amp;---...
+</code></pre>
index 90e696420565a7ab269c15289583bf4c413f3f86..8f5ee2ba2aaf09bf63aa56ab0700a7c8131709ce 100644 (file)
@@ -64,3 +64,9 @@ bar
 
 bar
 \end{verbatim}
+
+foo
+
+\begin{verbatim}
+-<>--&\&---...
+\end{verbatim}
index 4256b80e052a7bb22b0f1b2e3ce1d5419449ee6e..f72815ee043de1078c51db9b6444d8d4d7c50656 100644 (file)
@@ -48,3 +48,7 @@ foo
        bar
 
        bar
+
+foo
+
+       -<>--&\&---...
index 30885d494856e9071b50bb7cfed7fc7cfb75c52e..70814cef161123e648fd4a21f84c242076ef0bce 100644 (file)
@@ -65,7 +65,15 @@ code
 
 <h1 id="math">Math </h1>
 
-<p>math <span class="math">\({e}^{i\pi }+1=0\)</span></p>
+<p>foo <span class="math">\({e}^{i\pi }+1=0\)</span> bar</p>
+
+<p><span class="math">\[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \]</span></p>
+
+<p>foo <span class="math">\({e}^{i\pi }+1=0\)</span> bar</p>
+
+<p>foo <span class="math">\({e}^{i\pi }+1=0\)</span>, bar</p>
+
+<p><span class="math">\[{x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}\]</span></p>
 
 <h1 id="smartquotes">Smart Quotes </h1>
 
index b9477cfa2f79876e8ff5c7e4a9d6eaec817a309a..0bb4899d515e33b792a23d64823441b34574a0ac 100644 (file)
@@ -65,7 +65,15 @@ code
 
 <h1>Math </h1>
 
-<p>math ${e}^{i\pi }+1=0$</p>
+<p>foo \({e}^{i\pi }+1=0\) bar</p>
+
+<p>\[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \]</p>
+
+<p>foo ${e}^{i\pi }+1=0$ bar</p>
+
+<p>foo ${e}^{i\pi }+1=0$, bar</p>
+
+<p>$${x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}$$</p>
 
 <h1>Smart Quotes </h1>
 
index e088fafa466c856b8d7d411434fa54797086e6f4..26e7074d13c0dc1275984200180a4b83d4fa7da7 100644 (file)
@@ -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}
index 744aa3f955a4cdc06982626750c2849d47f0ed23..6f90471de1b0374bc4f8574e2d6112cb6f8d56e4 100644 (file)
@@ -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 #