Since the previous release: Machine::read_string() (the fs::path/std::string overload pair split); kdesc -c and -u rendered from the ref/ reflection klammerset; a fit column's tex width measured in TeX over every entry; @typeface resolving to the family its css declares (a store directory name now works in html) and hieroglyphs in @unicode_examples set in their typeface; the ansi target -- plain text with the type styles a terminal can show, identical to txt once the escape sequences are stripped -- with the txt @table carrying :header_style, :style and :hline; @block anchoring, @table spacing and the Image_quality state variable; and the rewritten doc/klammertext_for_llm.md.
129 lines
4.2 KiB
Python
129 lines
4.2 KiB
Python
import re
|
|
import textwrap
|
|
import pprint
|
|
|
|
import klammer_base
|
|
import phases
|
|
import kutil
|
|
import latex_util
|
|
import html_util
|
|
from html_util import E
|
|
import color
|
|
|
|
class Indent(klammer_base.Klammer_base):
|
|
def __init__(self, K):
|
|
super().__init__(K)
|
|
# Doesn't do anything now:
|
|
# self.s = kutil.escape(self.s)
|
|
if self.right < 0:
|
|
self.right = self.left
|
|
self.reduce = self.left + self.right
|
|
|
|
def html(self):
|
|
text_align = "justify" if not self.ragged else "left"
|
|
return E("div").body(self.s)\
|
|
.sty("margin", f"0.5rem {self.right}ex 0.5rem {self.left}ex")\
|
|
.sty("text-align", text_align)\
|
|
.str()
|
|
def tex(self):
|
|
if self.ragged:
|
|
self.s = "\\raggedright " + self.s
|
|
result = rf"\hspace*{{{self.left}ex}}" + latex_util.minipage(
|
|
self.s, rf"\linewidth - {self.reduce}ex", center=False)
|
|
result = latex_util.block(result)
|
|
return result
|
|
|
|
def txt(self):
|
|
indent = phases.txt_nbsp_marker() * self.left # a space that survives
|
|
width = int(self.Target_txt_width) - self.left - self.right + 1 # Off-by one for textwrap
|
|
result = self.s
|
|
result = re.sub("KK0022", '"', result)
|
|
result = indent + f"\n{indent}".join(textwrap.wrap(result, width=width, break_on_hyphens=True))
|
|
return result
|
|
|
|
|
|
class Note(klammer_base.Klammer_base):
|
|
def __init__(self, K):
|
|
super().__init__(K)
|
|
|
|
def html(self):
|
|
result = E("div").cls("box")\
|
|
.sty("width", f"{self.width*100}%")\
|
|
.sty("background-color", html_util.color(self.color))\
|
|
.sty("border-color", html_util.color(self.border_color))\
|
|
.sty("margin-left", "auto")\
|
|
.body(f"<b>{self.label}:</b> {self.s}")\
|
|
.str()
|
|
return result
|
|
|
|
def tex(self):
|
|
return latex_util.color_box(
|
|
f"\\textbf{{{self.label}:}} {self.s}",
|
|
self.width, self.color, self.border_color)
|
|
|
|
|
|
class Block(klammer_base.Klammer_base):
|
|
def __init__(self, K):
|
|
super().__init__(K)
|
|
|
|
def tex(self):
|
|
# NOT latex_util.block(): a textblock is absolutely positioned and
|
|
# does not participate in the normal flow, so breaking the paragraph
|
|
# around it would move the surrounding text.
|
|
#
|
|
# The trailing \par\kern0pt gives the block's vbox zero depth.
|
|
# textpos anchors :point against the box HEIGHT alone, so content
|
|
# whose last line has depth -- an @image, whose [c] minipage sits
|
|
# half below the baseline -- was anchored a quarter of its height
|
|
# too low (2in for a page-high picture) until 2026-09-08.
|
|
to_x, to_y = [float(e) for e in self.to.split()]
|
|
pt_x, pt_y = [float(e) for e in self.point.split()]
|
|
result = f"""
|
|
\\begin{{textblock}}{{{self.width}}}[{pt_x},{pt_y}]({to_x},{to_y})
|
|
\\setlength{{\\textwidth}}{{\\linewidth}}
|
|
\\vspace*{{-1\\parskip}}
|
|
{self.content.strip()}
|
|
\\par\\kern0pt
|
|
\\end{{textblock}}
|
|
"""
|
|
return result
|
|
|
|
|
|
class Lines(klammer_base.Klammer_base):
|
|
def __init__(self, K):
|
|
super().__init__(K)
|
|
self.lines = self.s.split("\n")
|
|
|
|
def html(self):
|
|
result = ""
|
|
for line in self.lines:
|
|
result += line + "<br/>\n"
|
|
return result
|
|
|
|
def tex(self):
|
|
return "\\\\\n".join(self.lines) + "\n"
|
|
|
|
def txt(self):
|
|
return self.lines
|
|
|
|
class Left_right(klammer_base.Klammer_base):
|
|
def __init__(self, K):
|
|
super().__init__(K)
|
|
self.rows = list(zip(self.parts[0], self.parts[1]))
|
|
|
|
def html(self):
|
|
result = ""
|
|
for left, right in self.rows:
|
|
result += E("div").body(
|
|
E("span").cls("left_right").body(left).str() + \
|
|
E("span").cls("left_right").sty("text-align", "right").body(right).str()).str();
|
|
result = E("p").body(result).str()
|
|
return result
|
|
|
|
def tex(self):
|
|
result = ""
|
|
for left, right in self.rows:
|
|
result += rf"\parbox{{\linewidth}}{{{left} \hfill {right}}}" + " \\\\\n"
|
|
result = result[:-3]
|
|
return result
|