]> git.scottworley.com Git - paperdoorknob/commitdiff
Render links as footnotes
authorScott Worley <scottworley@scottworley.com>
Sat, 30 Dec 2023 11:27:04 +0000 (03:27 -0800)
committerScott Worley <scottworley@scottworley.com>
Sat, 30 Dec 2023 11:27:04 +0000 (03:27 -0800)
paperdoorknob.py
paperdoorknob_test.py
testdata/this-is-glowfic.html
texify.py

index 4e7cdf6840b8bbd7fb6a227db538bc9db9cde915..6a556753479b96f55c535f53a14d6c444822edf0 100644 (file)
@@ -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))
index e01327caf070ed04dd43d0c2515a05246c6984e3..c4232829a9b41a940728cce880bc87fcee4a4613 100644 (file)
@@ -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}\?
 
index 207cdd187f3630508952332b270e27874114124f..158f5ad1b9eb5f08714b98a6bd25cfff59d6c639 100644 (file)
@@ -2,7 +2,7 @@
   <body>
     <div class="post-container post-post">
       <div class="post-edit-box">We don't want edit boxes</div>
-      <div class="post-content">This is glowfic</div>
+      <div class="post-content">This is <a href="https://glowfic.com">glowfic</a></div>
       <div class="post-footer">We don't want footers</div>
     </div>
     <div class="flat-post-replies">
index 83a8c671087d47fee49e25553be568032cf2f2c5..65b4230bc135db2cea845c7ae25e48be8e57f25a 100644 (file)
--- 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)