kdesc --rewrite from the reflection klammerset; txt caption rules the block's width

Assembled from klammertext-dev e99530408517. The katom rewrite patterns
are rendered from ref/ (a table in dispatch order, patterns through @c),
the procedural listing having left mac/; a plain-text caption's rule is
as long as the table or listing it captions; the editor-support comments
name the tools' new dev/ location.
This commit is contained in:
ack committed 2026-09-22 22:53:13 +02:00
1 parent 93d649e23c
commit c016b3e5f3
15 files changed
+101 -86

No files matched your search

+20
View File
@@ -244,10 +244,29 @@ def txt_insert_captions(text, K):
# "Listing 1", not "Listing 2". It was one counter for every label.
caption_numbers = {}
width = int(K.Target_txt_width)
verbatim = txt_verbatim_marker()
def block_width(lines):
# The visible width of the laid-out block adjacent to a caption:
# its lines carry the verbatim marker, and the first line that does
# not (or a blank line) ends the block.
widest = 0
for line in lines:
if not line.startswith(verbatim) or not line.strip():
break
widest = max(widest, txt_visible_length(line))
return widest
def replace(m):
indent_run, name, text = m.groups()
indent = len(indent_run) // len(nbsp)
indented_width = max(1, width - indent)
# The block the caption belongs to: below a top caption, above a
# bottom one. Its width is what the caption's rule is drawn to,
# so the rule under "Table 1 - Prices" is as long as the table's
# own rules, not as long as those words. (Before the match sits
# the caption line's own verbatim marker: drop that line.)
after = m.string[m.end():].split("\n")[1:]
before = m.string[:m.start()].split("\n")[:-1]
block = max(block_width(after), block_width(reversed(before)))
# An empty label means an unnumbered caption (":number false"). It
# must NOT take a number from the sequence: a reader counting the
# captions they can see would then find the next one a number
@@ -263,6 +282,7 @@ def txt_insert_captions(text, K):
if txt_visible_length(caption) > indented_width:
lines = txt_wrap(caption, indented_width)
line_length = max(txt_visible_length(e) for e in lines)
line_length = max(line_length, block - indent)
lines.append("-" * line_length)
lead = txt_verbatim_marker() + indent_run
# The first line's marker is already in the text, before the indent