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

+86 -8
View File
@@ -17,16 +17,94 @@ local function absolute(file)
return file:sub(1, 1) == '/' and file or source .. '/' .. file
end
-- Numbered, so that a/logo.svg and b/logo.svg do not share one PDF in the
-- build directory, where the second overwrote the first. The output of a source
-- path is remembered, so a drawing shown twice is converted once.
local count = 0
local converted_to = {}
local function number(value)
return value and tonumber(value:match('[-+]?[%d.]+')) or nil
end
local function attribute(tag, name)
local escaped = name:gsub('(%W)', '%%%1')
return tag:match(escaped .. '%s*=%s*"([^"]+)"')
or tag:match(escaped .. "%s*=%s*'([^']+)'")
end
local function linked_texts(svg, target)
local view = svg:match('<svg[%s%S]-viewBox%s*=%s*"([^"]+)"')
local min_x, min_y, width, height
if view then
min_x, min_y, width, height = view:match(
'^%s*([-+%d.]+)%s+([-+%d.]+)%s+([-+%d.]+)%s+([-+%d.]+)')
min_x, min_y, width, height = tonumber(min_x), tonumber(min_y),
tonumber(width), tonumber(height)
else
local root = svg:match('<svg[%s%S]-%>') or ''
min_x, min_y = 0, 0
width, height = number(attribute(root, 'width')),
number(attribute(root, 'height'))
end
if not width or not height or width == 0 or height == 0 then return end
local lines = {}
for opening, body in svg:gmatch('(<a%s+[%s%S]-%>)([%s%S]-)</a>') do
local href = attribute(opening, 'href')
if href and href:match('^#[%w_.:-]+$') then
for tag in body:gmatch('<text%s+[%s%S]-%>') do
local x, y = number(attribute(tag, 'x')), number(attribute(tag, 'y'))
local size = number(attribute(tag, 'font-size'))
local length = number(attribute(tag, 'textLength'))
if x and y and size and length then
local left = (x - min_x) / width
local bottom = 1 - (y + size * 0.25 - min_y) / height
local link_width = length / width
local link_height = size * 1.25 / height
table.insert(lines, string.format(
'\\businessimagelink{%s}{%.8f}{%.8f}{%.8f}{%.8f}',
href:sub(2), left, bottom, link_width, link_height))
end
end
end
end
-- A kept build folder still holds the links of the drawing that carried this
-- number before; the template would lay them over this one.
os.remove(target .. '.links.tex')
if #lines == 0 then return end
local sidecar, message = io.open(target .. '.links.tex', 'w')
if not sidecar then
error('the links of the drawing could not be written: ' .. tostring(message))
end
sidecar:write(table.concat(lines, '\n'), '\n')
sidecar:close()
end
function Image(image)
if not image.src:lower():match('%.svg$') then return nil end
local name = image.src:gsub('.*/', ''):gsub('%.[Ss][Vv][Gg]$', '') .. '.pdf'
local target = build .. '/' .. name
local converted, message = pcall(pandoc.pipe, 'inkscape',
{'--export-type=pdf', '--export-filename=' .. target,
absolute(image.src)}, '')
if not converted then
error('the drawing ' .. image.src .. ' could not be converted: '
.. tostring(message))
local source_path = absolute(image.src)
local target = converted_to[source_path]
if not target then
count = count + 1
local name = count .. '-'
.. image.src:gsub('.*/', ''):gsub('%.[Ss][Vv][Gg]$', '') .. '.pdf'
target = build .. '/' .. name
local converted, message = pcall(pandoc.pipe, 'inkscape',
{'--export-type=pdf', '--export-filename=' .. target, source_path}, '')
if not converted then
error('the drawing ' .. image.src .. ' could not be converted: '
.. tostring(message))
end
local handle, read_message = io.open(source_path, 'r')
if not handle then
error('the drawing ' .. image.src .. ' could not be read: '
.. tostring(read_message))
end
local svg = handle:read('*a')
handle:close()
linked_texts(svg, target)
converted_to[source_path] = target
end
image.src = target
return image