Files
business-suite/bin/code.lua
T
Marc WäckerlinandClaude Opus 5.5 d7aac52ac7 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>
2026-11-14 12:14:55 +01:00

88 lines
3.9 KiB
Lua

-- Copyright (c) 2026 Marc Wäckerlin. SPDX-License-Identifier: MIT
-- Long inline code gets the break opportunities a path or an identifier
-- offers, so that it wraps instead of standing outside the page.
--
-- `payment/stripe_utils/stripe_connector.py:214` is one word to LaTeX: it
-- carries no space, and hyphenation patterns do not apply to a typewriter face,
-- so the line runs over the right edge and the last characters stand next to
-- the paper. Measured over one report: 30 of 44 places where something left the
-- type area were spans of this kind, up to 44 points out.
--
-- A break is offered after the characters that structure such a name, and
-- before a capital that follows a small letter, which is where a reader of
-- `CreditCardCustomerBasicInfoSerializer` reads a boundary anyway. No hyphen is
-- inserted: a hyphen in a path would be read as part of the path.
--
-- Every span that carries such a boundary is treated, however short it is. The
-- rule used to start at 16 characters, on the reasoning that a shorter span
-- finds room on the next line by itself; a style guide that lists the names of
-- its convention refuted it. `--color-dark` and `--size-medium`, twelve and
-- thirteen characters, stood in a row with one space between them, and the two
-- lines carrying them ran 3.5 and 7.9 points past the edge while
-- `--color-fg-error` beside them broke after a hyphen — a break in one place
-- and none in the other, in one sentence.
--
-- A break that is OFFERED costs nothing: TeX takes it where a line cannot be
-- set otherwise and leaves the span whole everywhere else, so the short span is
-- still read in one piece on every line that has room for it.
-- Where the name really begins: a name may OPEN with the characters that
-- structure it — `--size-medium`, `.btn-primary`, `_private` — and there they
-- structure nothing. A break between the two hyphens of a custom property, or
-- directly behind them, leaves a line ending in `--` and a reader who copies
-- the name with two pieces, neither of which is the name. So the run at the
-- front belongs to the first piece, and the first break stands behind the first
-- piece of content.
--
-- And the first piece is set in a box, because the break this forbids is not
-- one this filter offers: TeX breaks after a hyphen of its own accord, in the
-- typewriter face as anywhere else. Measured on the rendered page after the
-- break points alone had been corrected — a line still ended in `--` with
-- `font-size-large` on the next one. A box has no break inside it and none
-- behind it where no space follows, which is exactly the two places.
local function opening(text)
local run = text:match('^[/._:%-]+')
return run and #run or 0
end
local function pieces(text)
local parts, current = {}, ''
local front = opening(text)
for index = 1, #text do
local char = text:sub(index, index)
local following = text:sub(index + 1, index + 1)
current = current .. char
local structural = index > front
and char:match('[/._:%-]') and following ~= ''
local camel = char:match('%l') and following:match('%u')
if structural or camel then
parts[#parts + 1] = current
current = ''
end
end
if current ~= '' then
parts[#parts + 1] = current
end
return parts
end
function Code(code)
if not FORMAT:match('latex') then return nil end
local parts = pieces(code.text)
if #parts < 2 then return nil end
local result = {}
for index, part in ipairs(parts) do
if index == 1 and opening(code.text) > 0 then
result[#result + 1] = pandoc.RawInline('latex', '\\mbox{')
result[#result + 1] = pandoc.Code(part)
result[#result + 1] = pandoc.RawInline('latex', '}')
else
result[#result + 1] = pandoc.Code(part)
end
if index < #parts then
result[#result + 1] = pandoc.RawInline('latex', '\\allowbreak{}')
end
end
return result
end