txt section numbering, @typeface :middle/:lift and html scale, NewGardinerOmni, html :leading (from dev 9fa469dd74ed)
Section headings under txt are numbered inside a @document only; @typeface gains :middle and :lift and its :scale now means the same in html and pdf; NewGardinerOmni ships (OFL 1.1, Mark-Jan Nederhof) and @egyptian / @chinese replace @cjk; @table :leading and :colsep reach html; kdesc --typeface help names the flag; @document.txt is a Python class. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
0ead40f272
commit
63956c00e5
26 files changed
+437
-173
No files matched your search
@@ -248,6 +248,50 @@ def txt_format_footnotes(text, K):
|
||||
+ label + " " + footnote + "\n\n")
|
||||
return result
|
||||
|
||||
|
||||
# Section numbering under txt (2026-09-18). Numbering is a DOCUMENT
|
||||
# service, as it is in html (a pass @document runs over the page) and tex
|
||||
# (LaTeX's own counters inside the document): a heading rendered outside
|
||||
# a @document -- kdesc's renders of the ref/ generators -- is not
|
||||
# numbered. Document.txt() (sks/document/document_txt.py) opens its
|
||||
# result with the document marker; Section.txt() emits a section marker
|
||||
# carrying the level and the :n override; this phase, first in the txt
|
||||
# and ansi lists, numbers the headings when the document marker is there
|
||||
# and strips every marker either way. A heading at a level with no
|
||||
# parent numbers as "0.1", as html and tex print it -- the txt target
|
||||
# does not diverge from them. The single-source functions are the
|
||||
# TODO #47 pattern.
|
||||
|
||||
def txt_document_marker():
|
||||
return "__KTEXTDOCUMENT__"
|
||||
|
||||
def txt_section_marker(level, n=-1):
|
||||
# LEVEL 0 is a part, 1-7 the sections; N > -1 sets the number.
|
||||
return f"__KTEXTSECTION__{level}__{n}__"
|
||||
|
||||
def txt_insert_section_numbers(text, K):
|
||||
# The marker is the first thing the document emits, but the result
|
||||
# reaches the phase behind whatever newlines the apply left in front.
|
||||
head = text.lstrip()
|
||||
in_document = head.startswith(txt_document_marker())
|
||||
if in_document:
|
||||
text = head[len(txt_document_marker()):].lstrip("\n")
|
||||
levels = [0] * 8 # 0: parts; 1-7: sections (parts do not reset them, as in LaTeX)
|
||||
marker_rgx = re.compile(r"__KTEXTSECTION__(\d+)__(-?\d+)__ ?")
|
||||
def number(match):
|
||||
if not in_document:
|
||||
return ""
|
||||
level, n = int(match.group(1)), int(match.group(2))
|
||||
levels[level] = n if n > -1 else levels[level] + 1
|
||||
if level == 0:
|
||||
return f"{levels[0]} " # a part resets nothing below it
|
||||
for i in range(level + 1, len(levels)):
|
||||
levels[i] = 0
|
||||
return ".".join(str(v) for v in levels[1:level + 1]) + " "
|
||||
return marker_rgx.sub(number, text)
|
||||
|
||||
# HTML
|
||||
|
||||
def html_footnote_marker():
|
||||
return "kt-footnote"
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ of this: neither the transforms nor the quoting reach it.
|
||||
' ' |
|
||||
~ __KTEXTNBSP__
|
||||
:after_apply
|
||||
phases.txt_insert_section_numbers ;
|
||||
phases.txt_format_footnotes ;
|
||||
phases.txt_insert_captions ;
|
||||
phases.txt_justify_blocks ;
|
||||
@@ -83,6 +84,7 @@ of this: neither the transforms nor the quoting reach it.
|
||||
@@@target ansi | Plain text with ANSI escape sequences for type styles
|
||||
:includes txt
|
||||
:after_apply
|
||||
phases.txt_insert_section_numbers ;
|
||||
phases.txt_format_footnotes ;
|
||||
phases.txt_insert_captions ;
|
||||
phases.txt_justify_blocks ;
|
||||
|
||||
Reference in new issue
Block a user