]> granicus.if.org Git - multimarkdown/commitdiff
ADDED: Support \autoref{} in LaTeX
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 12 Feb 2017 22:12:55 +0000 (17:12 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 12 Feb 2017 22:12:55 +0000 (17:12 -0500)
src/latex.c
tests/MMD6Tests/Advanced Headers.html
tests/MMD6Tests/Advanced Headers.htmlc
tests/MMD6Tests/Advanced Headers.tex
tests/MMD6Tests/Advanced Headers.text
tests/MMD6Tests/Integrated.html
tests/MMD6Tests/Integrated.htmlc
tests/MMD6Tests/Integrated.tex
tests/MMD6Tests/Integrated.text

index 4c17458dae25fefcd971a0eff9f2be4f1ba1ea0f..392112b17d444b8d5f90f6c4ec6f6b636fa55623 100644 (file)
@@ -203,9 +203,32 @@ void mmd_print_localized_char_latex(DString * out, unsigned short type, scratch_
 
 void mmd_export_link_latex(DString * out, const char * source, token * text, link * link, scratch_pad * scratch) {
        attr * a = link->attributes;
+       char * temp_char;
 
        if (link->url) {
-               printf("\\href{%s}", link->url);
+               if (link->url[0] == '#') {
+                       // Internal link
+                       if (text && text->child) {
+                               temp_char = label_from_token(source, text);
+
+                               if (strcmp(temp_char, &(link->url[1])) == 0) {
+                                       // [bar][bar] or [bar](#bar) or [bar]
+                                       printf("\\autoref{%s}", &(link->url)[1]);
+                               } else {
+                                       mmd_export_token_tree_latex(out, source, text->child, scratch);
+                                       print(" (");
+                                       printf("\\autoref{%s}", &(link->url)[1]);
+                                       print(")");
+                               }
+
+                               free(temp_char);
+                       } else {
+                               printf("\\autoref{%s}", &(link->url)[1]);
+                       }
+                       return;
+               } else {
+                       printf("\\href{%s}", link->url);                        
+               }
        } else
                print("\\href{}");
 
index c2735d9050bd80b3867d41035d4e521c90317e8a..6267cfc15344313ae29f0e4f2b649d6b3a6af0ba 100644 (file)
 <p>5</p>
 
 <h1 id="bar">foo </h1>
+
+<h1 id="foobar"><em>foo</em> bar </h1>
+
+<h1 id="foobar"><em>foo
+bar</em></h1>
+
+<p><a href="#bar">bar</a></p>
+
+<p><a href="#bar">foo</a></p>
\ No newline at end of file
index 40cfe909423354a6f81d373fe205bda4aca426eb..e3277a9186465096fc63d4ba7bf9ed5a01c44c33 100644 (file)
 <p>5</p>
 
 <h1>foo [bar]</h1>
+
+<h1><em>foo</em> bar </h1>
+
+<h1><em>foo
+bar</em></h1>
+
+<p>[bar]</p>
+
+<p>[foo][bar]</p>
index 3a996faa236617dbb8dbceaa1b11a58b708600c0..939b775a003a288f87455225265e6b0a1a3105b2 100644 (file)
@@ -4,16 +4,27 @@
 \part{foo}
 \label{bar}
 
-\part{foo [bar][bat]}
+\part{foo bar (\autoref{bat})}
 \label{foobarbat}
 
-\part{foo [bar][bat]}
+\part{foo \autoref{bar} }
 \label{bat}
 
-\part{foo [bar][bat]}
+\part{foo bar (\autoref{bat})}
 \label{baz}
 
 5
 
 \part{foo }
 \label{bar}
+
+\part{\emph{foo} bar }
+\label{foobar}
+
+\part{\emph{foo
+bar}}
+\label{foobar}
+
+\autoref{bar}
+
+foo (\autoref{bar})
index c6600bdf611f80ae88fec989ba25f0b23d304b9a..e834f1d8bce6c86d41bfe1072d9ef8b8851f162d 100644 (file)
 
 foo [bar]
 =========
+
+# *foo* bar #
+
+*foo
+bar*
+====
+
+[bar]
+
+[foo][bar]
index 0b22f41cdeb2202b226c05c6c549d1180ada47a3..7e9fa598db09b9a9f2d46bba590f6ea411b2202c 100644 (file)
@@ -55,6 +55,10 @@ code
 <figcaption>test</figcaption>
 </figure>
 
+<p><a href="#math">Math</a></p>
+
+<p><a href="#math">foo</a></p>
+
 <h1 id="math">Math </h1>
 
 <p>math <span class="math">\({e}^{i\pi }+1=0\)</span></p>
index e58e7145855025fd4cc4992860e1c9b1fce9aada..2fc962a853d37dd002817ed6861c74087b75237e 100644 (file)
@@ -55,6 +55,10 @@ code
 
 <p>![test](http://foo.bar/ &quot;title&quot; width=&quot;40px&quot; height=400px)</p>
 
+<p>[Math]</p>
+
+<p>[foo][math]</p>
+
 <h1>Math </h1>
 
 <p>math ${e}^{i\pi }+1=0$</p>
index 84dde238946fb0c447f9b7a433f0cbee04e1ba0a..d16d32f5c78479ee5dd7f4a063dd4bdf57a72eb4 100644 (file)
@@ -61,6 +61,9 @@ Cite.\citesyntax TBD
 
 \href{http://foo.net/}{link}\footnote{\href{http://foo.net/}{http:/\slash foo.net\slash }} and \href{http://bar.net}{link}\footnote{\href{http://bar.net}{http:/\slash bar.net}}
 
+\autoref{math}
+
+foo (\autoref{math})
 
 \part{Math }
 \label{math}
index 089e8754e94cf6de950b318b2376caa9a3cbca7e..7adf965b69e5aa0bd0f748fa9c3640ea1bf2e7a8 100644 (file)
@@ -56,6 +56,10 @@ Cite.[#Inline Citation]
 
 ![test](http://foo.bar/ "title" width="40px" height=400px)
 
+[Math]
+
+[foo][math]
+
 
 # Math #