feat: smolnet rewrites > [!kind] callout markers

With SMOLNET_CALLOUTS (kind -> label), the marker line becomes a bold
label and the passage stays a blockquote, instead of the literal
"[!ontology]" printing in the capsule. Unlisted kinds are left alone.
Default {} keeps other sites unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
randogoth 2026-10-22 11:25:13 +03:00
parent 8f3b26f219
commit b6418b090f

View file

@ -31,6 +31,8 @@ setting, and every setting has a default, so a site can switch it on with just
Notes section; off by default since not
every site using this plugin has been
checked for footnotes
SMOLNET_CALLOUTS {} callout kind -> label, for `> [!kind]`
blocks; see rewrite_callouts
Every run of links here is a **Markdown list**, which is what each format needs:
Mews Profile reads a dated link as a feed entry only when it starts a list item
@ -120,6 +122,9 @@ FOOTNOTE_REF = re.compile(r"\[\^([^\]]+)\]")
# citation it was meant to carry.
LINKREF_DEF = re.compile(r"^\[(\d+)\]:", re.MULTILINE)
# The opening line of a GitHub/Obsidian-style callout, "> [!kind] title".
CALLOUT = re.compile(r"^([ ]{0,3}>[ ]?)\[!(\w+)\][ \t]*(.*)$", re.MULTILINE)
def rot13(text):
"""The obfuscation used on addresses in the HTML templates."""
@ -322,6 +327,33 @@ def rewrite_footnotes(text, labels, warn):
return body.rstrip() + "\n\n" + "\n".join(notes) + "\n"
def rewrite_callouts(text, kinds):
"""Turn a `> [!kind]` marker into a bold label line, leaving the rest of
the passage an ordinary blockquote.
The HTML build renders these as boxes (an <aside>, via a Markdown
extension in the site itself). gemtext has nothing to draw a box with, and
a quote is the one block it does set apart, so the passage stays one; only
the marker would otherwise print literally as "[!ontology]". Kinds not in
`kinds` are left alone, matching the HTML side, which also only boxes the
kinds it was told about.
"""
if not kinds:
return text
kinds = {k.lower(): v for k, v in kinds.items()}
def sub(match):
kind = match.group(2).lower()
if kind not in kinds:
return match.group(0)
title = match.group(3).strip() or kinds[kind]
# The label as a paragraph of its own inside the quote, so it can't run
# into the passage's first sentence.
return "%s**%s**\n>" % (match.group(1), title)
return CALLOUT.sub(sub, text)
def toml_escape(value):
return str(value).replace("\\", "\\\\").replace('"', '\\"')
@ -384,6 +416,7 @@ class CapsuleGenerator(Generator):
s.get("LOSTIMAGES_DEAD_HOSTS", [])}
sidecar_name = s.get("SMOLNET_SIDECAR", ".itsybitsy.toml")
footnotes = s.get("SMOLNET_FOOTNOTES", False)
callouts = s.get("SMOLNET_CALLOUTS", {})
# kapara serves the same remark42 thread the HTML widget shows, over
# Gemini, Spartan and Nex. Articles only: the widget is on articles
# only, and a page with a thread nobody can reach from the site is a
@ -416,6 +449,7 @@ class CapsuleGenerator(Generator):
body = rewrite_html_links(body, urls, self._warn)
body = reveal_rot13(body, rot_attr)
body = drop_dead_images(body, dead_hosts)
body = rewrite_callouts(body, callouts)
if footnotes:
body = rewrite_footnotes(body, labels, self._warn)
# Blank lines, not newlines: a heading and the line under it are