]> git.scottworley.com Git - paperdoorknob/commitdiff
LaTeX output is a valid LaTeX file
authorScott Worley <scottworley@scottworley.com>
Fri, 1 Dec 2023 09:01:21 +0000 (01:01 -0800)
committerScott Worley <scottworley@scottworley.com>
Wed, 20 Dec 2023 01:37:10 +0000 (17:37 -0800)
default.nix
paperdoorknob.py
paperdoorknob_test.py

index 58f98862f305518503a2d8ee8896f882bb109897..3e02638098eb34a7f513f1a3701a4c8a3cde5828 100644 (file)
@@ -1,7 +1,8 @@
 { pkgs ? import <nixpkgs> { }, lint ? false }:
 pkgs.python3Packages.callPackage ({ lib, buildPythonPackage, makeWrapper
   , autopep8, mypy, pylint, beautifulsoup4, requests, requests-cache
-  , types-beautifulsoup4, types-requests, xdg-base-dirs, pandoc-cli }:
+  , texliveBasic, types-beautifulsoup4, types-requests, xdg-base-dirs
+  , pandoc-cli }:
   buildPythonPackage rec {
     pname = "paperdoorknob";
     version = "0.0.1";
@@ -9,7 +10,8 @@ pkgs.python3Packages.callPackage ({ lib, buildPythonPackage, makeWrapper
     nativeBuildInputs = [ makeWrapper ];
     propagatedBuildInputs =
       [ beautifulsoup4 requests requests-cache xdg-base-dirs ];
-    nativeCheckInputs = [ mypy pandoc-cli types-beautifulsoup4 types-requests ]
+    nativeCheckInputs =
+      [ mypy pandoc-cli texliveBasic types-beautifulsoup4 types-requests ]
       ++ lib.optionals lint [ autopep8 pylint ];
     doCheck = true;
     checkPhase = "./test.sh";
index 32daf4f4d9372b07ee1e5eb801037ea2efa129ad..8ab62f10b655f6b9f7c21cc4dd5a1f5379d066be 100644 (file)
@@ -84,9 +84,11 @@ def process(
         texout: IO[bytes],
         pandoc: str,
 ) -> None:
+    texout.write(b'\\documentclass{article}\n\\begin{document}\n')
     html = clean(fetch(url, session, timeout))
     for r in replies(html):
         texout.write(html_to_tex(pandoc, r))
+    texout.write(b'\\end{document}\n')
 
 
 def main() -> None:
index ee4de040173557d0e5d0d7e96cfafd68b1805f44..9ea877daa77ffdbe27469abaefc32ace1b493d4a 100644 (file)
@@ -7,6 +7,7 @@
 
 import unittest
 import io
+import subprocess
 import threading
 from http.server import BaseHTTPRequestHandler, HTTPServer
 import requests
@@ -129,9 +130,25 @@ class TestFetch(unittest.TestCase):
                 TIMEOUT,
                 buf,
                 'pandoc')
-            self.assertEqual(
-                buf.getvalue(),
-                b'This is glowfic\nYou \\emph{sure}?\nPretty sure.\n')
+            self.assertEqual(buf.getvalue(), b'''\\documentclass{article}
+\\begin{document}
+This is glowfic
+You \\emph{sure}?
+Pretty sure.
+\\end{document}
+''')
+
+    def testPDF(self) -> None:
+        with requests.session() as s:
+            with open("test.tex", 'wb') as out:
+                paperdoorknob.process(
+                    f"http://localhost:{self._port()}",
+                    s,
+                    TIMEOUT,
+                    out,
+                    'pandoc')
+            subprocess.run(['pdflatex', 'test.tex'],
+                           stdin=subprocess.DEVNULL, check=True)
 
 
 if __name__ == '__main__':