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:
ackandClaude Fable 5.1 committed 2026-09-16 16:59:49 +02:00
1 parent 9b0d0d7897
commit 0ead40f272
39 files changed
+734 -158

No files matched your search

+59 -31
View File
@@ -3,6 +3,7 @@ import re
import textwrap
import kutil
import klammer_base
import phases
import itertools
import math
from html_util import E
@@ -81,17 +82,42 @@ class Define(klammer_base.Klammer_base):
'c' : r'\normalfont\ttfamily',
's' : r'\normalfont\sffamily'}[self.style]
return f"{font} {s}"
# The "\hfill\newline" was to force the description to the next line even if the item was small:
# result = "\n\n".join([f"\\item[{{{fontify(term)}}}]\\hfill\n\\newline {definition}"
strut = r"\rule[-8pt]{0pt}{8pt}"
strut = r"\rule[-4pt]{0pt}{4pt}"
result = "\n\n".join([f"\\item[{{{fontify(term)}{strut}}}] {definition}"
for term,definition in self.items])
result = f"\\begin{{description}}[labelindent=12pt,nosep,itemsep=6pt,parsep=.5\\parskip,style=nextline]\n{result}\n\\end{{description}}"
options = "style=nextline" # See list/list.sty
result = f"\\begin{{description}}[{options}]\n{result}\n\\end{{description}}"
return result
# Needs to be implemented:
# def txt(self):
# return "TXT DEFINITIONS"
def txt(self):
# Plain text: each term on its own line at the block indent, its
# definition beneath it indented once more, items separated by a
# blank line. Every line begins with the nbsp marker, which is what
# tells the justification pass the block is already laid out
# (phases.txt_justify_blocks); a definition's own paragraphs are
# wrapped to the remaining measure, and a paragraph that is already
# laid out (it begins with the marker -- a @table inside the
# definition) is only indented further. The term takes :style as
# italic or bold, the styles a terminal can show.
nbsp = phases.txt_nbsp_marker()
indent = int(self.Target_txt_indent)
term_indent, def_indent = nbsp * indent, nbsp * (2 * indent)
measure = int(self.Target_txt_width) - 2 * indent
style = {"i": "italic", "b": "bold"}.get(self.style)
items = []
for term, definition in self.items:
term = term.strip()
if style and term:
term = phases.txt_style_marker(style) + term + phases.txt_style_marker(style, False)
paragraphs = []
for par in re.split(r"\n\s*\n", definition.strip()):
if phases.txt_is_laid_out(par):
paragraphs.append("\n".join(def_indent + line for line in par.split("\n")))
else:
paragraphs.append("\n".join(def_indent + line
for line in phases.txt_wrap(par, measure)))
items.append(term_indent + term + "\n" + "\n\n".join(paragraphs))
return phases.txt_lay_out("\n\n".join(items))
class Lines(klammer_base.Klammer_base):
@@ -114,30 +140,32 @@ class Lines(klammer_base.Klammer_base):
return self.s.strip()
class Columns(klammer_base.Klammer_base):
def __init__(self, K):
super().__init__(K)
def make_column_lists(lst, count):
cols = math.ceil(len(lst) / count)
result = []
for i in range(count):
#print(i * cols, (i + 1) * cols)
result.append(lst[i * cols : (i+1) * cols])
return list(itertools.zip_longest(*result, fillvalue=""))
def make_column_lists(self):
lst = [f"@{self.style} {e} {self.style}@" for e in self.items.split()]
cols = math.ceil(len(lst) / self.n)
result = []
for i in range(self.n):
result.append(lst[i * cols : (i+1) * cols])
return list(itertools.zip_longest(*result, fillvalue=""))
def xmake_column_lists(lst, column_count):
count = len(lst)
row_count = math.ceil(count / column_count)
print(count, column_count, row_count)
i = 0
while i < count:
i += 1
def columns(self):
rows = self.make_column_lists()
result = (f"@table :header false :number false :leading 1.0 "
f":hpos {self.hpos} :offset {self.offset} |\n")
for row in rows:
result += " | ".join(row) + " ||\n"
result += "table@\n"
return result
def html(self):
return self.columns()
def columns(K):
rows = make_column_lists(K.items.split(), K.n)
result = "@table\n" # :lines false :header_line false :leading 1.1 :vmargin false |\n"
for row in rows:
#print("row:", row)
result += " | ".join(row) + " ||\n"
result += "table@\n"
if K.K_target == "latex":
result = f"\\vspace*{{-12pt}}\n{result}"
return result
def tex(self):
return self.columns()
def txt(self):
return self.columns()