]> git.scottworley.com Git - paperdoorknob/blame - paperdoorknob.py
Less space between icon and post-separation line
[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
d2a41ff4 11from glowfic import chunkDOMs, 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
SW
20 spec.texout.write(b'''\\documentclass{article}
21\\usepackage{graphicx}
357f37be 22\\usepackage{wrapstuff}
d2a41ff4 23''')
e10b5b6f
SW
24 if spec.geometry is not None:
25 spec.texout.write(b'\\usepackage[' +
26 spec.geometry.encode('UTF-8') +
27 b']{geometry}\n')
28 spec.texout.write(b'\\begin{document}\n')
8be20b9d 29 html = parse(spec.htmlfilter(spec.fetcher.fetch(spec.url)))
85bcacb0 30 first = True
e6adf6ce 31 for r in chunkDOMs(html):
85bcacb0
SW
32 if first:
33 first = False
34 else:
35 # h/t https://tex.stackexchange.com/questions/309856
36 spec.texout.write(b'''
357f37be 37\\wrapstuffclear\\vspace{-.5\\ht\\strutbox}\\noindent\\hrulefill
85bcacb0
SW
38
39''')
8be20b9d 40 spec.domfilter(r)
d2a41ff4
SW
41 chunk = makeChunk(r, spec.images)
42 spec.texout.write(spec.layout.renderChunk(chunk))
23f31879 43 spec.texout.write(b'\\end{document}\n')
47cfa3cd
SW
44
45
92b11a10 46def main() -> None:
23f31879
SW
47 with spec_from_commandline_args() as spec:
48 process(spec)
92b11a10
SW
49
50
51if __name__ == '__main__':
52 main()