From b254976424d0f56fab14f8897dade345ce46a2d1 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Sat, 30 Dec 2023 03:27:04 -0800 Subject: [PATCH] Render links as footnotes --- paperdoorknob.py | 4 +++- paperdoorknob_test.py | 3 ++- testdata/this-is-glowfic.html | 2 +- texify.py | 3 +++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/paperdoorknob.py b/paperdoorknob.py index 4e7cdf6..6a55675 100644 --- a/paperdoorknob.py +++ b/paperdoorknob.py @@ -34,7 +34,9 @@ def process(spec: Spec) -> None: spec.texout.write(b'\\usepackage[' + spec.geometry.encode('UTF-8') + b']{geometry}\n') - spec.texout.write(b'\\begin{document}\n') + spec.texout.write(b'''\\begin{document} +\\newcommand{\\href}[2]{#2\\footnote{#1}} +''') url = flatURL(spec.url) html = parse(spec.htmlfilter(spec.fetcher.fetch(url))) num_chunks = ilen(chunkDOMs(html)) diff --git a/paperdoorknob_test.py b/paperdoorknob_test.py index e01327c..c423282 100644 --- a/paperdoorknob_test.py +++ b/paperdoorknob_test.py @@ -50,7 +50,8 @@ class BaseTestProcess(ABC): assert re.match(br'''\\documentclass{article} (\\usepackage{[a-z]+}\n)+\\usepackage\[margin=20mm\]{geometry} \\begin{document} -This is glowfic +\\newcommand{\\href}\[2\]{#2\\footnote{#1}} +This is \\href{https://glowfic.com}{glowfic} You \\emph{sure}\? diff --git a/testdata/this-is-glowfic.html b/testdata/this-is-glowfic.html index 207cdd1..158f5ad 100644 --- a/testdata/this-is-glowfic.html +++ b/testdata/this-is-glowfic.html @@ -2,7 +2,7 @@
We don't want edit boxes
-
This is glowfic
+
This is glowfic
diff --git a/texify.py b/texify.py index 83a8c67..65b4230 100644 --- a/texify.py +++ b/texify.py @@ -49,6 +49,9 @@ class DirectTexifier(Texifier): def texify(self, html: Tag) -> bytes: if html.name == 'em': return b'\\emph{' + self._texify_children(html).strip() + b'}\n' + if html.name == 'a' and 'href' in html.attrs: + return b'\\href{' + html.attrs['href'].encode( + 'UTF-8') + b'}{' + self._texify_children(html).strip() + b'}\n' return self._texify_children(html) -- 2.44.1