@link :section links to a section by its heading, with an alone value (from dev 831455f36fcd)
A section link names the TEXT of a heading: :section alone means the current file, a value names the file of the same @document that has it. Resolved by @document at assembly in html and tex; errors for a missing file, a missing title, a doubled title and a link outside a @document. The Markdown converter reads a Markdown anchor as a section link to the heading its slug names. Also from dev: the converter's four silent defects fixed and --chapter (9ae2c4cd), and the engine's alone-value error text. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
32aa47d41c
commit
f4dcdf3ffd
15 files changed
+594
-114
No files matched your search
+28
-12
@@ -6,8 +6,25 @@ import klammer_base
|
||||
import urllib
|
||||
import kutil
|
||||
|
||||
def html_link(target, link_text, is_section, no_quotation_marks):
|
||||
# [__link__target__text__]
|
||||
# :section (argtype section_link, Andy 2026-10-12) is absent ("false"),
|
||||
# written alone ("true": the section is in the current file) or written
|
||||
# with a basename (the file that has the section). A section link is
|
||||
# resolved by @document when it assembles its files (sks/document/
|
||||
# section_link.h), from this marker: the heading's text and the file, ""
|
||||
# meaning the current one, separated by KTSL because either may contain an
|
||||
# underscore.
|
||||
def section_file(section):
|
||||
"""The file a :section value names: "" for the current file, None when
|
||||
the link is not a section link at all."""
|
||||
s = str(section)
|
||||
if s in ("", "false", "False"):
|
||||
return None
|
||||
return "" if s in ("true", "True") else s
|
||||
|
||||
def section_marker(title, file):
|
||||
return f"__seclink__{title}__KTSL__{file}__"
|
||||
|
||||
def html_link(target, link_text, is_section, no_quotation_marks, file=""):
|
||||
if not link_text:
|
||||
if is_section:
|
||||
link_text = target if no_quotation_marks else f"“{target}”"
|
||||
@@ -16,14 +33,11 @@ def html_link(target, link_text, is_section, no_quotation_marks):
|
||||
link_text = re.sub('/', '/<wbr/>', target)
|
||||
link_text = re.sub('/<wbr/>/<wbr/>', '//', link_text)
|
||||
link_text = f'<tt>{link_text}</tt>'
|
||||
target = f"[{target}]" if is_section else target
|
||||
#result = f"[__link__{target}__{link_text}__]"
|
||||
#return result
|
||||
|
||||
if target.startswith("http") or ".html" in target:
|
||||
if is_section:
|
||||
url = section_marker(target, file)
|
||||
elif target.startswith("http") or ".html" in target:
|
||||
url = target
|
||||
elif is_section:
|
||||
url = f"__sectionlink__{target}__"
|
||||
else:
|
||||
url = f"^#{target}"
|
||||
result = f'<a href="{url}">{link_text}</a>'
|
||||
@@ -38,7 +52,7 @@ def add_latex_footnote_if_necessary(url, link_text):
|
||||
result += f'\\footnote{{\\\rule{{0pt}}{{12pt}}\\texttt{{{escaped_url}}}}}'
|
||||
return result
|
||||
|
||||
def latex_link(target, link_text, is_section, no_quotation_marks, add_footnote):
|
||||
def latex_link(target, link_text, is_section, no_quotation_marks, add_footnote, file=""):
|
||||
if target.startswith("http"):
|
||||
if link_text and link_text != "URL":
|
||||
result = f"#/ \\href{{{target}}}{{{link_text}}} #/"
|
||||
@@ -48,7 +62,7 @@ def latex_link(target, link_text, is_section, no_quotation_marks, add_footnote):
|
||||
elif is_section:
|
||||
if not link_text:
|
||||
link_text = target if no_quotation_marks else f"``{target}''"
|
||||
result = f"\\hyperlink{{__seclink__{target}__}}{{{link_text}}}"
|
||||
result = f"\\hyperlink{{{section_marker(target, file)}}}{{{link_text}}}"
|
||||
else:
|
||||
result = f"\\hyperlink{{{target}}}{{{link_text}}}"
|
||||
# if add_footnote:
|
||||
@@ -63,10 +77,12 @@ class Link(klammer_base.Klammer_base):
|
||||
# self.show("Link")
|
||||
|
||||
def html(self):
|
||||
return html_link(self.target, self.text, self.section, self.nq)
|
||||
file = section_file(self.section)
|
||||
return html_link(self.target, self.text, file is not None, self.nq, file or "")
|
||||
|
||||
def tex(self):
|
||||
return latex_link(self.target, self.text, self.section, self.nq, self.footnote)
|
||||
file = section_file(self.section)
|
||||
return latex_link(self.target, self.text, file is not None, self.nq, self.footnote, file or "")
|
||||
|
||||
def txt(self):
|
||||
text = f'{self.text} ' if self.text else ''
|
||||
|
||||
Reference in new issue
Block a user