]> git.scottworley.com Git - paperdoorknob/blobdiff - texify.py
Texifier interface
[paperdoorknob] / texify.py
diff --git a/texify.py b/texify.py
new file mode 100644 (file)
index 0000000..4fb1557
--- /dev/null
+++ b/texify.py
@@ -0,0 +1,29 @@
+# paperdoorknob: Print glowfic
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3.
+
+
+from abc import ABC, abstractmethod
+import subprocess
+
+from bs4.element import Tag
+
+
+class Texifier(ABC):
+    @abstractmethod
+    def texify(self, html: Tag) -> bytes:
+        raise NotImplementedError()
+
+
+class PandocTexifier(Texifier):
+
+    def __init__(self, pandoc_path: str) -> None:
+        self._pandoc_path = pandoc_path
+
+    def texify(self, html: Tag) -> bytes:
+        return subprocess.run([self._pandoc_path, '--from=html', '--to=latex'],
+                              input=html.encode(),
+                              stdout=subprocess.PIPE,
+                              check=True).stdout