]> git.scottworley.com Git - paperdoorknob/blob - texify.py
4fb15575832c66cbd99d4d12bbb9644cee1bfdaa
[paperdoorknob] / texify.py
1 # paperdoorknob: Print glowfic
2 #
3 # This program is free software: you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License as published by the
5 # Free Software Foundation, version 3.
6
7
8 from abc import ABC, abstractmethod
9 import subprocess
10
11 from bs4.element import Tag
12
13
14 class Texifier(ABC):
15 @abstractmethod
16 def texify(self, html: Tag) -> bytes:
17 raise NotImplementedError()
18
19
20 class PandocTexifier(Texifier):
21
22 def __init__(self, pandoc_path: str) -> None:
23 self._pandoc_path = pandoc_path
24
25 def texify(self, html: Tag) -> bytes:
26 return subprocess.run([self._pandoc_path, '--from=html', '--to=latex'],
27 input=html.encode(),
28 stdout=subprocess.PIPE,
29 check=True).stdout