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{}");
<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
\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})
<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>