1 # paperdoorknob: Print glowfic
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.
9 from typing
import Any
, Iterable
11 from bs4
import BeautifulSoup
13 from args
import spec_from_commandline_args
14 from glowfic
import chunkDOMs
, flatURL
, makeChunk
18 def parse(content
: bytes) -> BeautifulSoup
:
19 return BeautifulSoup(content
, 'html.parser')
22 def ilen(it
: Iterable
[Any
]) -> int:
23 return sum(1 for _
in it
)
26 def process(spec
: Spec
) -> None:
27 spec
.texout
.write(b
'''\\documentclass{article}
28 \\usepackage{booktabs}
29 \\usepackage{graphicx}
30 \\usepackage{longtable}
32 \\usepackage{varwidth}
33 \\usepackage{wrapstuff}
35 if spec
.geometry
is not None:
36 spec
.texout
.write(b
'\\usepackage[' +
37 spec
.geometry
.encode('UTF-8') +
39 spec
.texout
.write(b
'\\begin{document}\n')
40 url
= flatURL(spec
.url
)
41 html
= parse(spec
.htmlfilter(spec
.fetcher
.fetch(url
)))
42 num_chunks
= ilen(chunkDOMs(html
))
43 for i
, r
in enumerate(chunkDOMs(html
)):
44 percent
= 100.0 * i
/ num_chunks
46 f
'Processing chunk {i} of {num_chunks} ({percent:.1f}%)',
50 chunk
= makeChunk(r
, spec
.images
)
51 spec
.texout
.write(spec
.texfilter(spec
.layout
.renderChunk(chunk
)))
52 spec
.texout
.write(b
'\\end{document}\n')
56 with spec_from_commandline_args() as spec
:
60 if __name__
== '__main__':