Escaping, table layout, and document fixes

Quoted Klammertext specials (^@ ^| ^# ^^ ^: ^*) and ^'...'^ regions now
survive re-processing (held as escape markers until final output);
:after_apply phase functions receive and return raw target text.

Tables: :hpos element position (center|left|right|<length>) replaces the
unimplemented :center/:indent; the ranged cell override is renamed
:justify; :column_width works in html (colgroup widths) and gains
'fill' -- the remaining width, capped at the column's widest entry, in
both targets; a table wider than the text column warns on the console;
table edges without an outer line set their text flush on the margins.

@document: no empty title bar for untitled documents; @vfill fills to
the bottom of the window in html (pure CSS); @vspace in plain text;
new @dot klammer; monospace email links.
This commit is contained in:
2026-07-25 21:16:21 +02:00
parent 4262fc6136
commit d61336b191
26 changed files with 650 additions and 75 deletions

View File

@@ -160,6 +160,14 @@
display: inline-flex;
}
/* A length :hpos; the margin-left comes as an inline style. */
.hpos_indent {
display: flex;
flex-direction: row;
align-items: center;
justify-content: left;
}
.hpos_margin {
margin: 0 1em 0 1em;
}

View File

@@ -309,7 +309,7 @@ namespace html {
elts.push_back(elt("style", css));
}
if (!title.empty()) {
if (!trim(title).empty()) {
elts.push_back(elt("title", trim(title)));
}
HTML result = elt("head", elts);
@@ -486,11 +486,15 @@ namespace html {
elements_t body {};
if (!title.empty()) {
elements_t title_bar {};
title_bar.push_back(elt("span", trim(title)).attr("id", "title_text"));
if (!trim(title).empty()) {
title_bar.push_back(elt("span", trim(title)).attr("id", "title_text"));
}
if (!logo.empty()) {
title_bar.push_back(elt("span", trim(logo)).attr("id", "logo"));
}
body.push_back(elt("div", title_bar).attr("id", "title"));
if (!title_bar.empty()) {
body.push_back(elt("div", title_bar).attr("id", "title"));
}
}
if (!nav.empty()) {
body.push_back(navigation(max_level));
@@ -538,12 +542,18 @@ namespace html {
void add_title(elements_t& body, std::string title, std::string logo)
{
// No title bar at all when there is nothing to put in it (an
// untitled document); a logo alone still gets the bar.
elements_t title_bar {};
title_bar.push_back(elt("span", trim(title)).attr("id", "title_text"));
if (!trim(title).empty()) {
title_bar.push_back(elt("span", trim(title)).attr("id", "title_text"));
}
if (!logo.empty()) {
title_bar.push_back(elt("span", trim(logo)).attr("id", "logo"));
}
body.push_back(elt("div", title_bar).attr("id", "title"));
if (!title_bar.empty()) {
body.push_back(elt("div", title_bar).attr("id", "title"));
}
}
void add_nav(elements_t& body, int max_level)

View File

@@ -193,8 +193,27 @@ def element_tag(element):
def font_class(font):
return {"r" : "", "i" : "ritalic", "t" : "monospace", "s" : "sanserif"}[font]
def hpos_container(element, hpos):
# Wrap element in its horizontal-position container. hpos is left,
# center, right, none, or a length, which becomes the left margin
# (the tex counterparts are the \LTleft glue for tables and the
# \hspace* in latex_util.caption_wrapper).
style = None
if hpos not in ("left", "center", "right", "none"):
length, _, _ = kutil.parse_length("html", hpos, 1)
style = f"margin-left: {length}"
hpos = "indent"
result = E("div").cls("hpos_" + hpos).body(element)
if style:
result.attr("style", style)
if hpos not in ("center", "indent"):
result.cls("hpos_margin")
return result
def add_caption(element, caption_label, number, caption_text,
font_symbol="i", hpos="center", side="bottom", as_string=True, font_size=.9):
font_symbol="i", hpos="center", side="bottom", as_string=True,
font_size=.9, width=None, max_width=None):
tag = element_tag(element)
# Caption
caption = ""
@@ -232,12 +251,19 @@ def add_caption(element, caption_label, number, caption_text,
#print("-"*80)
element = E("div").cls("caption_" + side).attr("data-label", caption_label).body(element)
if width:
# The element's width (e.g. a table's :column_width total) lives
# on this wrapper: the element fills it, and the caption tracks
# the element.
element.attr("style", f"width: {width}")
elif max_width:
# A content-sized element (a 'fill' table): the wrapper shrinks
# to it but never past the text column, so the element wraps at
# narrow windows instead of overflowing.
element.attr("style", f"max-width: {max_width}")
result = element
result = E("div").cls("hpos_" + hpos).body(element)
if hpos != "center":
result = result.cls("hpos_margin")
result = hpos_container(element, hpos)
if number:
result.cls("element_container")

View File

@@ -55,15 +55,21 @@ def minipage(content, width="\\textwidth", vertical="c", center=True, vmargin=""
return result
def caption_wrapper(element, hpos, bottom_margin=.67):
# hpos is left, center, right, none (no wrapper), or a length, which
# becomes the left margin. The element is a box on a line inside a
# full-width minipage; \hfill on the empty side pushes it into place.
vmargin = f"{bottom_margin}\\baselineskip"
result = element
if hpos == "center":
result = minipage(element, vmargin=vmargin)
elif hpos == "left":
result = minipage("\\hfill" + element, vmargin=vmargin)
elif hpos == "right":
result = minipage(element + "\\hfill", vmargin=vmargin)
return result
return minipage(element, vmargin=vmargin)
if hpos == "left":
return minipage(element + "\\hfill", vmargin=vmargin, center=False)
if hpos == "right":
return minipage("\\hfill" + element, vmargin=vmargin, center=False)
if hpos == "none":
return element
length, _, _ = kutil.parse_length("tex", hpos, 1)
return minipage(f"\\hspace*{{{length}}}" + element + "\\hfill",
vmargin=vmargin, center=False)
def make_caption_text(number, label, text, font_symbol, font_size):
caption = None

View File

@@ -304,17 +304,28 @@ def make_pdf_from_tex(filename, K, twice=True):
os.system('rm -rf {}/{}.{}'.format(dirname, basename, unused_ext))
# Emitted by @vspace.txt (sks/block/block.k), one marker per line of space.
# An @eval result consisting only of whitespace is trimmed away by the
# Klammermachine, so vertical space must travel as markers and become
# newlines here, after blank-line runs have been normalized.
vspace_marker = "__VSPACE__"
def justify_blocks(text, K=None):
rgx = re.compile("\n\n+", re.S)
delim = '__DIVIDE__'
text = rgx.sub(delim, text)
text = re.sub("\n\n+", delim, text)
result = ""
for par in text.split(delim):
#print(par)
if par[0] not in {' ', '['}:
stripped = par.strip()
n = stripped.count(vspace_marker)
if n and stripped == vspace_marker * n:
# A paragraph of only @vspace markers: n blank lines in addition
# to the normal paragraph separation.
result += "\n" * n
continue
if par and par[0] not in {' ', '['}:
par = "\n".join(textwrap.wrap(par, width=80))
result += par + "\n\n"
return result
return result.replace(vspace_marker, "\n")

View File

@@ -44,7 +44,7 @@ The LaTeX transformations supported by the SKS are:
@@@
@@@target tex | LaTeX
:escape \ \textbackslash{} & \& { \{ } \} $ \$ % \% _ \_
:escape \ \textbackslash{} & \& { \{ } \} $ \$ % \% _ \_ ^# \^# ^^ \textasciicircum{}
@@@
@@@target pdf | PDF from LaTeX