]> git.scottworley.com Git - paperdoorknob/blame - paperdoorknob.py
Use LaTeX packages: longtable and booktabs
[paperdoorknob] / paperdoorknob.py
CommitLineData
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 8from bs4 import BeautifulSoup
23f31879
SW
9
10from args import spec_from_commandline_args
1452f8d3 11from glowfic import chunkDOMs, flatURL, makeChunk
23f31879 12from spec import Spec
92b11a10
SW
13
14
bf06f467
SW
15def parse(content: bytes) -> BeautifulSoup:
16 return BeautifulSoup(content, 'html.parser')
b25a2f90
SW
17
18
23f31879 19def process(spec: Spec) -> None:
d2a41ff4 20 spec.texout.write(b'''\\documentclass{article}
a5f4539c 21\\usepackage{booktabs}
d2a41ff4 22\\usepackage{graphicx}
a5f4539c 23\\usepackage{longtable}
23dabdf5 24\\usepackage{varwidth}
357f37be 25\\usepackage{wrapstuff}
d2a41ff4 26''')
e10b5b6f
SW
27 if spec.geometry is not None:
28 spec.texout.write(b'\\usepackage[' +
29 spec.geometry.encode('UTF-8') +
30 b']{geometry}\n')
31 spec.texout.write(b'\\begin{document}\n')
1452f8d3
SW
32 url = flatURL(spec.url)
33 html = parse(spec.htmlfilter(spec.fetcher.fetch(url)))
e6adf6ce 34 for r in chunkDOMs(html):
8be20b9d 35 spec.domfilter(r)
d2a41ff4
SW
36 chunk = makeChunk(r, spec.images)
37 spec.texout.write(spec.layout.renderChunk(chunk))
23f31879 38 spec.texout.write(b'\\end{document}\n')
47cfa3cd
SW
39
40
92b11a10 41def main() -> None:
23f31879
SW
42 with spec_from_commandline_args() as spec:
43 process(spec)
92b11a10
SW
44
45
46if __name__ == '__main__':
47 main()