Width and height argtypes, kdesc --argtypes from ref/, txt @define/@left_right/@columns, kdiag --check value validation (from dev d6993110e9b3)
Also: the klammertext argtype (descriptions kept as source), txt table wrapping and :hpos/:offset, @c between ‹ ›, txt section headings, the ktext newline-only trim, capitalize(), and the argtype test suite. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
9b0d0d7897
commit
0ead40f272
39 files changed
+734
-158
No files matched your search
+23
-2
@@ -25,6 +25,26 @@ def txt_vspace_marker():
|
||||
def txt_nbsp_marker():
|
||||
return "__KTEXTNBSP__"
|
||||
|
||||
# A ZERO-WIDTH mark that says "this line is already laid out" (2026-09-16).
|
||||
# The justification pass takes a paragraph beginning with a space or the
|
||||
# nbsp marker as verbatim, and until now that was the only way a block
|
||||
# could say so -- which broke the moment a block was flush left: a @table
|
||||
# with :hpos left :offset 0 (what @columns emits) began with its first
|
||||
# cell, so its rows were re-flowed into one line. A block that lays itself
|
||||
# out puts this at the start of every line (txt_lay_out); it is nothing to
|
||||
# txt_visible_length and is removed at the end of txt_justify_blocks.
|
||||
def txt_verbatim_marker():
|
||||
return "__KTEXTVERBATIM__"
|
||||
|
||||
def txt_lay_out(text):
|
||||
"""text with every line marked as already laid out."""
|
||||
mark = txt_verbatim_marker()
|
||||
return "\n".join(mark + line for line in text.split("\n"))
|
||||
|
||||
def txt_is_laid_out(par):
|
||||
"""True for a paragraph the justification pass must leave alone."""
|
||||
return par.startswith((" ", txt_nbsp_marker(), txt_verbatim_marker()))
|
||||
|
||||
# The type-style markers, emitted by @b.txt, @i.txt, @u.txt and @ri.txt
|
||||
# (sks/font/font.k) around their text. Plain text has no bold, but a
|
||||
# terminal does: the txt target STRIPS these in its last phase
|
||||
@@ -68,7 +88,7 @@ def txt_visible_length(s):
|
||||
"""How many columns s occupies once its markers resolve: a KTESC
|
||||
marker is one glyph, an nbsp marker one space, a style marker nothing.
|
||||
len() is the wrong measure for anything laid out (see txt_util)."""
|
||||
s = _STYLE_MARKER_RGX.sub("", s)
|
||||
s = _STYLE_MARKER_RGX.sub("", s).replace(txt_verbatim_marker(), "")
|
||||
return len(klammer_base.unescape_ktesc(s).replace(txt_nbsp_marker(), " "))
|
||||
|
||||
def txt_wrap(text, width, subsequent_indent=""):
|
||||
@@ -159,7 +179,7 @@ def txt_justify_blocks(text, K):
|
||||
# branch that had nothing to do also did not copy the text through.
|
||||
# An indented paragraph vanished from the output with no error.
|
||||
nbsp = txt_nbsp_marker()
|
||||
if par and par[0] != ' ' and not par.startswith(nbsp):
|
||||
if par and not txt_is_laid_out(par):
|
||||
label = re.match("(?:" + re.escape(nbsp) + r")*\[\d+\] ", par)
|
||||
par = "\n".join(txt_wrap(
|
||||
par, int(K.Target_txt_width),
|
||||
@@ -167,6 +187,7 @@ def txt_justify_blocks(text, K):
|
||||
result += par + "\n\n"
|
||||
result = re.sub(" *" + txt_vspace_marker() + " *", "\n", result)
|
||||
result = re.sub(r"\n? *" + txt_nl_marker() + r" *\n?", "\n", result)
|
||||
result = result.replace(txt_verbatim_marker(), "")
|
||||
result = result.replace(txt_nbsp_marker(), " ")
|
||||
return result
|
||||
|
||||
|
||||
Reference in new issue
Block a user