]> git.scottworley.com Git - paperdoorknob/blame - texify.py
Texifier interface
[paperdoorknob] / texify.py
CommitLineData
79631507
SW
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
8from abc import ABC, abstractmethod
9import subprocess
10
11from bs4.element import Tag
12
13
14class Texifier(ABC):
15 @abstractmethod
16 def texify(self, html: Tag) -> bytes:
17 raise NotImplementedError()
18
19
20class 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