]>
Commit | Line | Data |
---|---|---|
92b11a10 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 | ||
136277e3 | 8 | from bs4 import BeautifulSoup |
23f31879 SW |
9 | |
10 | from args import spec_from_commandline_args | |
e6adf6ce | 11 | from glowfic import chunkDOMs |
23f31879 | 12 | from spec import Spec |
92b11a10 SW |
13 | |
14 | ||
bf06f467 SW |
15 | def parse(content: bytes) -> BeautifulSoup: |
16 | return BeautifulSoup(content, 'html.parser') | |
b25a2f90 SW |
17 | |
18 | ||
23f31879 | 19 | def process(spec: Spec) -> None: |
8d583d5b | 20 | spec.texout.write(b'\\documentclass{article}\n\\usepackage{wrapfig}\n') |
e10b5b6f SW |
21 | if spec.geometry is not None: |
22 | spec.texout.write(b'\\usepackage[' + | |
23 | spec.geometry.encode('UTF-8') + | |
24 | b']{geometry}\n') | |
25 | spec.texout.write(b'\\begin{document}\n') | |
8be20b9d | 26 | html = parse(spec.htmlfilter(spec.fetcher.fetch(spec.url))) |
e6adf6ce | 27 | for r in chunkDOMs(html): |
8be20b9d | 28 | spec.domfilter(r) |
23f31879 SW |
29 | spec.texout.write(spec.texifier.texify(r)) |
30 | spec.texout.write(b'\\end{document}\n') | |
47cfa3cd SW |
31 | |
32 | ||
92b11a10 | 33 | def main() -> None: |
23f31879 SW |
34 | with spec_from_commandline_args() as spec: |
35 | process(spec) | |
92b11a10 SW |
36 | |
37 | ||
38 | if __name__ == '__main__': | |
39 | main() |