Skip to content

Commit

Permalink
Only let LaTeX's link renderer prototype produce \ref for rel. autolinks
Browse files Browse the repository at this point in the history
Previously in LaTeX, both `<#fragment>` and `[some text](#fragment
"title")` would produce the `\ref{fragment}` command with the default
link renderer prototype. Now, only `<#fragment>` produces
`\ref{fragment}`, whereas `[some text](#fragment "title")` becomes
`some text\footnote{title: \url{#fragment}}`. Closes #127.
  • Loading branch information
Witiko committed May 17, 2022
1 parent a8e5838 commit 5b93bd8
Showing 1 changed file with 48 additions and 16 deletions.
64 changes: 48 additions & 16 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -23141,31 +23141,63 @@ end
\endgroup
% \end{macrocode}
% \begin{markdown}
% If the URL begins with a hash sign, then we assume that it is a relative
% reference. Otherwise, we assume that it is an absolute URL.
% If the label and the fully-escaped URI are equivalent and the title is
% empty, assume that the link is an autolink. Otherwise, assume that the
% link is either direct or indirect.
% \end{markdown}
% \begin{macrocode}
\tl_set:Nx
\l_tmpa_tl
{ \str_range:nnn { ##3 } { 1 } { 1 } }
\str_if_eq:NNTF
\l_tmpa_tl
\c_hash_str
\tl_set:Nn \l_tmpa_tl { ##1 }
\tl_set:Nn \l_tmpb_tl { ##2 }
\bool_set:Nn
\l_tmpa_bool
{
\exp_args:No
\markdownLaTeXRendererRelativeLink
{ \str_range:nnn { ##3 } { 2 } { -1 } }
\tl_if_eq_p:NN
\l_tmpa_tl
\l_tmpb_tl
}
\tl_set:Nn \l_tmpa_tl { ##4 }
\bool_set:Nn
\l_tmpb_bool
{
\tl_if_empty_p:N
\l_tmpa_tl
}
\bool_if:nTF
{
\l_tmpa_bool && \l_tmpb_bool
}
{
\markdownLaTeXRendererAutolink { ##2 } { ##3 }
}{
\markdownLaTeXRendererAbsoluteLink { ##1 } { ##2 } { ##3 } { ##4 }
\markdownLaTeXRendererDirectOrIndirectLink { ##1 } { ##2 } { ##3 } { ##4 }
}
}
\next
}
\def\markdownLaTeXRendererAutolink#1#2{%
% \end{macrocode}
% \begin{markdown}
% If the URL begins with a hash sign, then we assume that it is a relative
% reference. Otherwise, we assume that it is an absolute URL.
% \end{markdown}
% \begin{macrocode}
\tl_set:Nx
\l_tmpa_tl
{ \str_range:nnn { #2 } { 1 } { 1 } }
\str_if_eq:NNTF
\l_tmpa_tl
\c_hash_str
{
\exp_args:No
\ref
{ \str_range:nnn { #2 } { 2 } { -1 } }
}{
\url { #2 }
}
}
\ExplSyntaxOff
\def\markdownLaTeXRendererAbsoluteLink#1#2#3#4{%
#1\footnote{\ifx\empty#4\empty\else#4: \fi\texttt<\url{#3}\texttt>}}
\def\markdownLaTeXRendererRelativeLink#1{%
\ref{#1}}
\def\markdownLaTeXRendererDirectOrIndirectLink#1#2#3#4{%
#1\footnote{\ifx\empty#4\empty\else#4:~\fi\texttt<\url{#3}\texttt>}}
% \end{macrocode}
% \par
% \begin{markdown}
Expand Down

0 comments on commit 5b93bd8

Please sign in to comment.