rename hrefExternal to href and href to hrefWithoutArrow

This commit is contained in:
Sina Atalay 2023-10-27 22:48:54 +02:00
parent 945abba84f
commit cfba6bcdc0
6 changed files with 37 additions and 32 deletions

View File

@ -30,7 +30,7 @@ def markdown_to_latex(markdown_string: str) -> str:
will return:
`#!pytjon "This is a \\textbf{bold} text with a \\hrefExternal{https://google.com}{\\textit{link}}."`
`#!pytjon "This is a \\textbf{bold} text with a \\href{https://google.com}{\\textit{link}}."`
Args:
markdown_string (str): The markdown string to convert.
@ -49,7 +49,7 @@ def markdown_to_latex(markdown_string: str) -> str:
link_url = link[1]
old_link_string = f"[{link_text}]({link_url})"
new_link_string = "\\hrefExternal{" + link_url + "}{" + link_text + "}"
new_link_string = "\\href{" + link_url + "}{" + link_text + "}"
markdown_string = markdown_string.replace(old_link_string, new_link_string)
@ -400,7 +400,6 @@ def run_latex(latex_file_path: str) -> str:
text=True,
) as latex_process:
output, error = latex_process.communicate()
output.split("\n")
if latex_process.returncode != 0:
# Find the error line:

View File

@ -109,7 +109,10 @@
}%
}%
\newcommand{\hrefExternal}[2]{\href{#1}{#2\, \raisebox{.1ex}{\footnotesize \faExternalLink*}}} % new command for external links
% save the original href command in a new command:
\let\hrefWithoutArrow\href
% new command for external links:
\renewcommand{\href}[2]{\hrefWithoutArrow{#1}{#2\, \raisebox{.1ex}{\footnotesize \faExternalLink*}}}
\begin{document}
((* if theme_options.show_last_updated_date *))

View File

@ -66,7 +66,7 @@
<<authors|join(", ")|make_it_italic(cv.name)>>
DOI: \hrefExternal{<<doi_url>>}{<<doi>>}
DOI: \href{<<doi_url>>}{<<doi>>}
&
<<date>>
\end{tabularx}

View File

@ -1,30 +1,30 @@
((# Each macro in here is a link with an icon for header. #))
((* macro LinkedIn(username, url) -*))
\mbox{\href{<<url>>}{{\small\faLinkedinIn}\hspace{0.13cm}<<username>>}}
\mbox{\hrefWithoutArrow{<<url>>}{{\small\faLinkedinIn}\hspace{0.13cm}<<username>>}}
((*- endmacro *))
((* macro GitHub(username, url) -*))
\mbox{\href{<<url>>}{{\small\faGithub}\hspace{0.13cm}<<username>>}}
\mbox{\hrefWithoutArrow{<<url>>}{{\small\faGithub}\hspace{0.13cm}<<username>>}}
((*- endmacro *))
((* macro Instagram(username, url) -*))
\mbox{\href{<<url>>}{{\small\faInstagram}\hspace{0.13cm}<<username>>}}
\mbox{\hrefWithoutArrow{<<url>>}{{\small\faInstagram}\hspace{0.13cm}<<username>>}}
((*- endmacro *))
((* macro Orcid(username, url) -*))
\mbox{\href{<<url>>}{{\small\faOrcid}\hspace{0.13cm}<<username>>}}
\mbox{\hrefWithoutArrow{<<url>>}{{\small\faOrcid}\hspace{0.13cm}<<username>>}}
((*- endmacro *))
((* macro phone(number, url) -*))
\mbox{\href{<<url|replace("-","")>>}{{\footnotesize\faPhone*}\hspace{0.13cm}<<number|replace("tel:", "")|replace("-"," ")>>}}
\mbox{\hrefWithoutArrow{<<url|replace("-","")>>}{{\footnotesize\faPhone*}\hspace{0.13cm}<<number|replace("tel:", "")|replace("-"," ")>>}}
((*- endmacro *))
((* macro email(email, url) -*))
\mbox{\href{<<url>>}{{\small\faEnvelope[regular]}\hspace{0.13cm}<<email>>}}
\mbox{\hrefWithoutArrow{<<url>>}{{\small\faEnvelope[regular]}\hspace{0.13cm}<<email>>}}
((*- endmacro *))
((* macro website(url, dummy) -*))
\mbox{\href{<<url>>}{{\small\faLink}\hspace{0.13cm}<<url|replace("https://","")|replace("/","")>>}}
\mbox{\hrefWithoutArrow{<<url>>}{{\small\faLink}\hspace{0.13cm}<<url|replace("https://","")|replace("/","")>>}}
((*- endmacro *))
((* macro location(location, url) -*))

View File

@ -106,7 +106,10 @@
}%
}%
\newcommand{\hrefExternal}[2]{\href{#1}{#2\, \raisebox{.1ex}{\footnotesize \faExternalLink*}}} % new command for external links
% save the original href command in a new command:
\let\hrefWithoutArrow\href
% new command for external links:
\renewcommand{\href}[2]{\hrefWithoutArrow{#1}{#2\, \raisebox{.1ex}{\footnotesize \faExternalLink*}}}
\begin{document}
\placelastupdatedtext
@ -118,15 +121,15 @@
\normalsize
\mbox{{\small\faMapMarker*}\hspace{0.13cm}Geneva, Switzerland}
\hspace{0.5cm}
\mbox{\href{tel:+905413769286}{{\footnotesize\faPhone*}\hspace{0.13cm}+90 541 376 92 86}}
\mbox{\hrefWithoutArrow{tel:+905413769286}{{\footnotesize\faPhone*}\hspace{0.13cm}+90 541 376 92 86}}
\hspace{0.5cm}
\mbox{\href{mailto:john@doe.com}{{\small\faEnvelope[regular]}\hspace{0.13cm}john@doe.com}}
\mbox{\hrefWithoutArrow{mailto:john@doe.com}{{\small\faEnvelope[regular]}\hspace{0.13cm}john@doe.com}}
\hspace{0.5cm}
\mbox{\href{https://example.com/}{{\small\faLink}\hspace{0.13cm}example.com}}
\mbox{\hrefWithoutArrow{https://example.com/}{{\small\faLink}\hspace{0.13cm}example.com}}
\hspace{0.5cm}
\mbox{\href{https://www.linkedin.com/in/dummy}{{\small\faLinkedinIn}\hspace{0.13cm}dummy}}
\mbox{\hrefWithoutArrow{https://www.linkedin.com/in/dummy}{{\small\faLinkedinIn}\hspace{0.13cm}dummy}}
\hspace{0.5cm}
\mbox{\href{https://www.github.com/sinaatalay}{{\small\faGithub}\hspace{0.13cm}sinaatalay}}
\mbox{\hrefWithoutArrow{https://www.github.com/sinaatalay}{{\small\faGithub}\hspace{0.13cm}sinaatalay}}
\end{header}
@ -138,7 +141,7 @@
\textbf{Bogazici University}, Mechanical Engineering
\vspace*{0.12 cm}
\begin{highlights}
\item GPA: 3.80/4.00 (\hrefExternal{https://example.com/}{Transcript})
\item GPA: 3.80/4.00 (\href{https://example.com/}{Transcript})
\item Test 1
\item Test 2
\end{highlights}
@ -196,7 +199,7 @@
\section{Academic Projects}
\begin{tabularx}{\textwidth}{K{0.2 cm} R{3.6 cm}}
\textbf{Academic Project 1}, \hrefExternal{https://example.com/}{view on my website}
\textbf{Academic Project 1}, \href{https://example.com/}{view on my website}
\vspace*{0.12 cm}
\begin{highlights}
\item Test 1
@ -210,7 +213,7 @@
\vspace*{0.12 cm}
\begin{tabularx}{\textwidth}{K{0.2 cm} R{3.6 cm}}
\textbf{Academic Project 2}, \hrefExternal{https://example.com/}{view on my website}
\textbf{Academic Project 2}, \href{https://example.com/}{view on my website}
\vspace*{0.12 cm}
\begin{highlights}
\item Test 1
@ -222,7 +225,7 @@
\vspace*{0.12 cm}
\begin{tabularx}{\textwidth}{K{0.2 cm} R{3.6 cm}}
\textbf{Academic Project 3}, \hrefExternal{https://example.com/}{view on my website}
\textbf{Academic Project 3}, \href{https://example.com/}{view on my website}
\vspace*{0.12 cm}
\begin{highlights}
\item Test 1
@ -292,7 +295,7 @@
\setlength{\leftskip}{0.2 cm}
\setlength{\rightskip}{0.2 cm}
\textbf{IELTS:} 9.0/9.0 (\hrefExternal{https://example.com/}{Score Report})
\textbf{IELTS:} 9.0/9.0 (\href{https://example.com/}{Score Report})
\setlength{\leftskip}{0cm}
\setlength{\rightskip}{0cm}
@ -334,7 +337,7 @@
Cetin Yilmaz, Gregory M Hulbert, Noboru Kikuchi
DOI: \hrefExternal{https://doi.org/10.1103/PhysRevB.76.054309}{10.1103/PhysRevB.76.054309}
DOI: \href{https://doi.org/10.1103/PhysRevB.76.054309}{10.1103/PhysRevB.76.054309}
&
Aug. 2007
\end{tabularx}

View File

@ -10,36 +10,36 @@ from rendercv import rendering, data_model
class TestRendering(unittest.TestCase):
def test_markdown_to_latex(self):
input = "[link](www.example.com)"
expected = r"\hrefExternal{www.example.com}{link}"
expected = r"\href{www.example.com}{link}"
output = rendering.markdown_to_latex(input)
with self.subTest(msg="only one link"):
self.assertEqual(output, expected)
input = "[link](www.example.com) and [link2](www.example2.com)"
expected = (
r"\hrefExternal{www.example.com}{link} and"
r" \hrefExternal{www.example2.com}{link2}"
r"\href{www.example.com}{link} and"
r" \href{www.example2.com}{link2}"
)
output = rendering.markdown_to_latex(input)
with self.subTest(msg="two links"):
self.assertEqual(output, expected)
input = "[**link**](www.example.com)"
expected = r"\hrefExternal{www.example.com}{\textbf{link}}"
expected = r"\href{www.example.com}{\textbf{link}}"
output = rendering.markdown_to_latex(input)
with self.subTest(msg="bold link"):
self.assertEqual(output, expected)
input = "[*link*](www.example.com)"
expected = r"\hrefExternal{www.example.com}{\textit{link}}"
expected = r"\href{www.example.com}{\textit{link}}"
output = rendering.markdown_to_latex(input)
with self.subTest(msg="italic link"):
self.assertEqual(output, expected)
input = "[*link*](www.example.com) and [**link2**](www.example2.com)"
expected = (
r"\hrefExternal{www.example.com}{\textit{link}} and"
r" \hrefExternal{www.example2.com}{\textbf{link2}}"
r"\href{www.example.com}{\textit{link}} and"
r" \href{www.example2.com}{\textbf{link2}}"
)
output = rendering.markdown_to_latex(input)
with self.subTest(msg="italic and bold links"):
@ -48,7 +48,7 @@ class TestRendering(unittest.TestCase):
input = "**bold**, *italic*, and [link](www.example.com)"
expected = (
r"\textbf{bold}, \textit{italic}, and"
r" \hrefExternal{www.example.com}{link}"
r" \href{www.example.com}{link}"
)
output = rendering.markdown_to_latex(input)
with self.subTest(msg="bold, italic, and link"):