1.0.2: converter searches no subfolders, safer filters, forms, links and watermark

A document at the root of a checkout of 68377 folders needed 56 minutes,
because the converter named the suite, the document folder and the build folder
with `//` in TEXINPUTS; it now names them without recursion and the same
document converts in 11.5 seconds. A file below the document no longer replaces
a package of TeX Live.

The security review of the pending changes found four defects, each fixed with
a test proven red against the old files and green against the new ones twice:
an HTML table read in an empty sandbox, so an iframe opens no address; form
labels written through the LaTeX writer, so they are set as text; the form
pattern scans a line once instead of quadratically; a kept build folder no
longer lays the links of an earlier drawing over a new one. The form tests
remove the PDF of an earlier run before each conversion.

Also carried: forms out of Markdown, link colours from the company, clickable
links in prose, HTML tables and SVG drawings, the watermark, and the further
changes of 1.0.1 and 1.0.2 in the CHANGELOG.

npm test: 1232 of 1232 checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Marc WäckerlinandClaude Opus 5.5 committed 2026-11-14 12:14:55 +01:00
1 parent adc58e19d7
commit d7aac52ac7
28 files changed
+3918 -137

No files matched your search

+265
View File
@@ -86,6 +86,27 @@ def pair_document():
return "".join(parts)
def level_document():
"""The fourth and the fifth heading level, over every distance to the foot.
Both keep the shape their class gives them and run into the paragraph they
open, and both go through the same reservation as the three levels above:
a `####` out of Markdown is the fourth, and a level that misses the
reservation leaves its heading at the foot of a page while what it
announces begins on the next. Only `\\section` and `\\subsection` were ever
built by a test, so the claim about these two rested on the code alone.
"""
parts = [HEAD]
for level in ("paragraph", "subparagraph"):
for case in range(CASES):
parts.append("\\newpage\n")
parts.append("Filler line.\\par\n" * case)
parts.append("\\%s{%s case %d}\n" % (level, level.title(), case))
parts.append(long_table("%s cell case %d" % (level.title(), case)))
parts.append("\\end{document}\n")
return "".join(parts)
def sweep_document():
parts = [HEAD]
for case in range(CASES):
@@ -131,6 +152,16 @@ Dolor sit amet.
\end{document}
"""
HEADLINE_ONE = HEADLINE % ""
# A company whose lockup is wide: a long name, a long address and a logo of four
# ems. The head used to divide its line by a fixed share, 0.45 of it for the
# logo, and this block needs 0.57 — the logo then stood 65.11 points past the
# right edge of the paper and the annotation of its link lay outside the page
# box, measured on 2026-10-06.
HEADLINE_WIDE = HEADLINE.replace(
"\\usepackage{nordwind}",
"\\usepackage[logoheight=4em]{nordwind}") % (
"\\businessidentity{name={Nordwind Industriebeteiligungen},\n"
" address={https://nordwind-industriebeteiligungen.example}}\n")
# The same head with the lockup of two lines. The heading on the left has to
# stand on the line of the NAME, the first of the two, and not on the middle of
# a block that has grown a second line.
@@ -154,6 +185,47 @@ PICTURES = r"""\documentclass[a4paper,10pt]{article}
"""
def list_document():
"""Three headings, each followed by a list, and a table under the last.
A list sets an `\\everypar` of its own, so the forgetting that the first
paragraph after a heading does never runs. Where a heading does not ask
whether the announcement above it is still the one directly above, every
following heading takes over the number of the first, and the table at the
end writes its measurement under that number: the room for everything in
between is then reserved in front of the first heading.
"""
parts = [HEAD, "\\section{Ergebnisse}\n"]
for number in (1, 2):
parts.append("\\begin{itemize}\n\\item Erster Punkt der Liste\n"
"\\item Zweiter Punkt der Liste\n\\end{itemize}\n")
parts.append("\\section{Abschnitt %d}\n" % number)
parts.append(table("Letzte Zeile"))
parts.append("\\end{document}\n")
return "".join(parts)
# A picture with its caption, once short enough for one line and once long
# enough for two. The caption belongs to the picture over it, and a picture that
# stands alone is centred on the line, so the caption is centred too.
CAPTIONS = r"""\documentclass[a4paper,10pt]{article}
\usepackage{nordwind}
\begin{document}
\pagestyle{empty}
\begin{figure}[h]
\businessgraphic{example-image-16x9}
\caption{Kurze Legende}
\end{figure}
\end{document}
"""
CAPTIONS_LONG = CAPTIONS.replace(
"Kurze Legende",
"Eine Legende, die so lang ist, dass sie über die ganze Zeile reicht und "
"auf einer zweiten weitergeht, weil eine Legende aus mehreren Zeilen "
"anders ausgerichtet werden kann als eine aus einer einzigen, und beide "
"Fälle hier gemessen werden sollen")
# The same raster picture in a document that allows it a tenth of enlargement
# and no more: 401.5 points wide by itself, so 441.6 with the option below,
# where the line would otherwise give it 540.6.
@@ -342,6 +414,27 @@ def together(check):
f"{sentence} and its table on page {cell}")
def levels(check):
"""The fourth and the fifth level hold their table like the three above.
A heading that runs into its paragraph is still an announcement, and the
reservation reaches it through the same wrapper as every other level. The
fixture pushes each of the two down the page line by line over sixteen
distances to the foot, each with a table under it that asks for far more
room than a heading does by itself.
"""
source = support.write("levels.tex", level_document())
pdf, _ = build(source, EXAMPLES)
count = support.pages(pdf)
for level in ("Paragraph", "Subparagraph"):
for case in range(CASES):
heading = page_of(pdf, "%s case %d" % (level, case), count)
cell = page_of(pdf, "%s cell case %d" % (level, case), count)
check.that(heading and cell and heading == cell,
f"{level.lower()} case {case}: the heading stands on "
f"page {heading} and its table on page {cell}")
def foot(check):
"""What a document puts in the inner corner of the foot stays in the foot."""
source = support.write("foot.tex", FOOT)
@@ -590,6 +683,173 @@ def head_line(check):
"not on one line")
def wide_logo(check):
"""The logo takes the room it needs, and the running head takes the rest.
How much of the line a logo needs follows from the name, the address and the
height the document asks for, and no share of the line fits every company.
What is measured is the rendered page: the ink of the head ends inside the
text block, the build reports no box over the edge, and the heading on the
left still arrives.
"""
source = support.write("headlinewide.tex", HEADLINE_WIDE)
pdf, log = build(source, EXAMPLES)
with open(log, encoding="utf-8", errors="replace") as handle:
complaints = [line for line in handle.read().splitlines()
if line.startswith("Overfull \\hbox")]
check.that(not complaints,
"a wide lockup makes the head run over: "
+ "; ".join(complaints[:2]))
page = Page(pdf, 1)
blocks = bands(page)
check.that(blocks, "the page with the wide lockup carries no ink")
if not blocks:
return
factor = 72.0 / page.dpi
right = max(x for y in blocks[0] for x in range(page.width)
if page.dark(x, y)) * factor
# The text block ends one centimetre from the right edge of A4, and the
# glyphs may reach their own side bearing beyond the ink of the drawing.
edge = 595.28 - 28.45
check.that(right <= edge + 1,
f"the head ends at {right:.1f} points and the text block at "
f"{edge:.1f}")
heading = first_glyph(page, blocks[0][0], blocks[0][-1] + 1, 0,
page.width // 2)
check.that(heading, "the running head lost its room beside the wide logo")
def after_list(check):
"""A heading after a list announces for itself, not for the one above it.
Two headings in a row are one announcement, and the lower one takes over the
number of the upper. Between them, though, stands a list, so they are not in
a row at all. Measured in the aux file, where every reservation stands with
the number it belongs to, and on the page: the first heading has to stay on
the page it begins, and the table has to reserve its own room, a few lines,
instead of the whole distance from the first heading down to itself.
"""
source = support.write("afterlist.tex", list_document())
pdf, _ = build(source, EXAMPLES)
aux = os.path.join(os.path.dirname(pdf), "afterlist.aux")
with open(aux, encoding="utf-8", errors="replace") as handle:
reserved = [float(points) for points in re.findall(
r"\\business@need\{\d+\}\{([0-9.]+)pt\}", handle.read())]
check.that(reserved, "the table recorded no reservation at all")
if reserved:
check.that(max(reserved) < 200,
f"the table reserves {max(reserved):.0f} points, the "
"distance from a heading several lists further up")
check.that(support.pages(pdf) == 1,
f"the document of three headings runs over "
f"{support.pages(pdf)} pages")
first = support.words(pdf, 1)
check.that(any(word[0] == "Ergebnisse" for word in first),
"the first heading was pushed off page 1 by the reservation")
# The same page twice: once with the word across it, once without. The word is
# long enough to be measured as a band of ink and short enough to be read.
WATERMARK = r"""\documentclass[a4paper,10pt]{article}
\usepackage[%s]{nordwind}
\begin{document}
\section{Lorem}
Dolor sit amet, consetetur sadipscing elitr.
\end{document}
"""
def watermark(check):
"""The word of a draft lies across the page, and only where it is asked for.
It is set once and scaled to four fifths of the diagonal of the paper in
use, turned by the angle of that diagonal, so it lies along the page at
every paper size; a size in centimetres fits one paper and one word. What
is measured is the ink: the page with the word carries it over the whole
height and width of the text block, the page without it carries only its
own lines, and the word is light enough to read the page through it.
"""
plain, _ = build(support.write("nowatermark.tex", WATERMARK % ""),
EXAMPLES)
marked, _ = build(support.write("watermark.tex", WATERMARK % "draft"),
EXAMPLES)
quiet, loud = Page(plain, 1), Page(marked, 1)
# The word is as quiet as the paper allows, so the reader of the raster has
# to be told what counts as ink here: anything that is not the white of the
# page. The ordinary threshold of a layout test sees type and would report
# the page with the word as empty of it.
def tinted(page):
return [(x, y) for y in range(page.height)
for x in range(page.width)
if page.pixels[y * page.width + x] < 250]
light = tinted(loud)
check.that(len(light) > 20 * len(tinted(quiet)),
f"the page with the word carries {len(light)} tinted pixels and "
f"the page without it {len(tinted(quiet))}")
if not light:
return
factor = 72.0 / loud.dpi
width = (max(x for x, _ in light) - min(x for x, _ in light)) * factor
height = (max(y for _, y in light) - min(y for _, y in light)) * factor
check.that(width > 400,
f"the word spans {width:.0f} points across the page")
check.that(height > 400,
f"the word reaches over {height:.0f} points of the height")
# And it stays on the paper: a word too large for the sheet is cut at the
# edge, which is what a size written in centimetres does to a long word.
check.that(min(x for x, _ in light) > 2 and min(y for _, y in light) > 2,
"the word is cut at the top or the left edge of the sheet")
check.that(max(x for x, _ in light) < loud.width - 3
and max(y for _, y in light) < loud.height - 3,
"the word is cut at the bottom or the right edge of the sheet")
# That a page without the option carries no word is the first check above:
# the tinted pixels of the two pages are a factor of twenty apart, and an
# absolute number would measure the type and the logo of the page, which
# carry grey edges of their own.
def caption(check):
"""The caption stands centred under its picture, over one line and over two.
A picture that stands alone is centred on the line, and its caption used to
begin at the left edge of the text: the two then read as two things. What is
measured is the rendered page — the ink of the caption against the ink of the
picture over it.
"""
for what, fixture, lines in (("one line", CAPTIONS, 1),
("two lines", CAPTIONS_LONG, 2)):
source = support.write("caption%d.tex" % lines, fixture)
pdf, _ = build(source, EXAMPLES)
page = Page(pdf, 1)
blocks = bands(page)
# The picture is the tallest band of the page; the head and the folio
# stand on it too, so neither its place nor its number is assumed.
tallest = max(range(len(blocks)),
key=lambda index: len(blocks[index]))
picture = blocks[tallest]
columns = page.ink_columns(picture[0], picture[-1] + 1)
middle = (columns[0] + columns[-1]) / 2
# What follows the picture within a line of it is its caption; what
# stands further down belongs to the page.
step = int(round(2 * page.dpi / 72.0 * 10))
found, previous = [], picture
for band in blocks[tallest + 1:]:
if band[0] - previous[-1] > step:
break
found.append(band)
previous = band
check.that(len(found) == lines,
f"the caption of {what} came out in {len(found)} lines")
for number, band in enumerate(found, 1):
text = page.ink_columns(band[0], band[-1] + 1)
centre = (text[0] + text[-1]) / 2
apart = abs(centre - middle) * 72.0 / page.dpi
check.that(apart < 3,
f"line {number} of the caption of {what} stands "
f"{apart:.1f} points beside the middle of its picture")
def opening(check):
"""The title block brings the distance under it, and nothing adds to it.
@@ -734,12 +994,17 @@ def main():
pairs(check)
pictures(check)
head_line(check)
wide_logo(check)
caption(check)
watermark(check)
after_list(check)
opening(check)
edges(check)
headroom(check)
foot(check)
left_edge(check)
together(check)
levels(check)
return check.done()