From cfba6bcdc0ad2492b7041fceb941d7f61a7dc066 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Fri, 27 Oct 2023 22:48:54 +0200 Subject: [PATCH] rename hrefExternal to href and href to hrefWithoutArrow --- rendercv/rendering.py | 5 ++-- rendercv/templates/classic/classic.tex.j2 | 5 +++- .../templates/classic/components/entry.tex.j2 | 2 +- .../components/header_connections.tex.j2 | 14 +++++----- tests/reference_files/John_Doe_CV_test.tex | 27 ++++++++++--------- tests/test_rendering.py | 16 +++++------ 6 files changed, 37 insertions(+), 32 deletions(-) diff --git a/rendercv/rendering.py b/rendercv/rendering.py index 97e9faf..bdc020b 100644 --- a/rendercv/rendering.py +++ b/rendercv/rendering.py @@ -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: diff --git a/rendercv/templates/classic/classic.tex.j2 b/rendercv/templates/classic/classic.tex.j2 index c0fc93e..7eaea83 100644 --- a/rendercv/templates/classic/classic.tex.j2 +++ b/rendercv/templates/classic/classic.tex.j2 @@ -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 *)) diff --git a/rendercv/templates/classic/components/entry.tex.j2 b/rendercv/templates/classic/components/entry.tex.j2 index 1f1db87..43a1415 100644 --- a/rendercv/templates/classic/components/entry.tex.j2 +++ b/rendercv/templates/classic/components/entry.tex.j2 @@ -66,7 +66,7 @@ <> - DOI: \hrefExternal{<>}{<>} + DOI: \href{<>}{<>} & <> \end{tabularx} diff --git a/rendercv/templates/classic/components/header_connections.tex.j2 b/rendercv/templates/classic/components/header_connections.tex.j2 index b51bf41..a8e3f74 100644 --- a/rendercv/templates/classic/components/header_connections.tex.j2 +++ b/rendercv/templates/classic/components/header_connections.tex.j2 @@ -1,30 +1,30 @@ ((# Each macro in here is a link with an icon for header. #)) ((* macro LinkedIn(username, url) -*)) -\mbox{\href{<>}{{\small\faLinkedinIn}\hspace{0.13cm}<>}} +\mbox{\hrefWithoutArrow{<>}{{\small\faLinkedinIn}\hspace{0.13cm}<>}} ((*- endmacro *)) ((* macro GitHub(username, url) -*)) -\mbox{\href{<>}{{\small\faGithub}\hspace{0.13cm}<>}} +\mbox{\hrefWithoutArrow{<>}{{\small\faGithub}\hspace{0.13cm}<>}} ((*- endmacro *)) ((* macro Instagram(username, url) -*)) -\mbox{\href{<>}{{\small\faInstagram}\hspace{0.13cm}<>}} +\mbox{\hrefWithoutArrow{<>}{{\small\faInstagram}\hspace{0.13cm}<>}} ((*- endmacro *)) ((* macro Orcid(username, url) -*)) -\mbox{\href{<>}{{\small\faOrcid}\hspace{0.13cm}<>}} +\mbox{\hrefWithoutArrow{<>}{{\small\faOrcid}\hspace{0.13cm}<>}} ((*- endmacro *)) ((* macro phone(number, url) -*)) -\mbox{\href{<>}{{\footnotesize\faPhone*}\hspace{0.13cm}<>}} +\mbox{\hrefWithoutArrow{<>}{{\footnotesize\faPhone*}\hspace{0.13cm}<>}} ((*- endmacro *)) ((* macro email(email, url) -*)) -\mbox{\href{<>}{{\small\faEnvelope[regular]}\hspace{0.13cm}<>}} +\mbox{\hrefWithoutArrow{<>}{{\small\faEnvelope[regular]}\hspace{0.13cm}<>}} ((*- endmacro *)) ((* macro website(url, dummy) -*)) -\mbox{\href{<>}{{\small\faLink}\hspace{0.13cm}<>}} +\mbox{\hrefWithoutArrow{<>}{{\small\faLink}\hspace{0.13cm}<>}} ((*- endmacro *)) ((* macro location(location, url) -*)) diff --git a/tests/reference_files/John_Doe_CV_test.tex b/tests/reference_files/John_Doe_CV_test.tex index 8ba26e4..7c9bd91 100644 --- a/tests/reference_files/John_Doe_CV_test.tex +++ b/tests/reference_files/John_Doe_CV_test.tex @@ -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} diff --git a/tests/test_rendering.py b/tests/test_rendering.py index 83ecd41..cb2a353 100644 --- a/tests/test_rendering.py +++ b/tests/test_rendering.py @@ -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"):