From: Scott Worley Date: Sat, 30 Dec 2023 11:27:04 +0000 (-0800) Subject: Render links as footnotes X-Git-Url: http://git.scottworley.com/paperdoorknob/commitdiff_plain/b254976424d0f56fab14f8897dade345ce46a2d1?ds=inline;hp=372211762c57033dfef33075bd593ec5d426f3c7 Render links as footnotes --- 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)