A QR is drawn from its link, not pasted in as art

The three codes on the Support page were half-block art pasted into
support.md, and markdown had been quietly shearing them. A module row whose
first module is light opens on a *space*, and every CommonMark parser eats
leading whitespace on a continuation line — so four of the fifteen rows in the
Buy-me-a-coffee code, and rows in the other two, were rendered one module to
the left of where they belong. A sheared row is not a QR; a phone gets
nothing.

Markdown grows one construct instead: a fence tagged `qr`, whose body is a URL
and whose rendering is the code for it, through the same `qr.qr_text` widget
the channel and contact share popups draw. So the link is written once, the
code can never drift from it, and a QR looks the same everywhere in MeshTerm
— black on white, which is what makes it read under any terminal palette
rather than inverted on a dark one.

The three fences replace 45 lines of art.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-09-02 08:38:36 -04:00
1 parent 211f38255b
commit 155c0b5b21
2 files changed
+47

No files matched your search

+27
View File
@@ -23,6 +23,8 @@ imported from somewhere else:
* Lists hang on a bullet in a two-column grid, so a wrapped item aligns under its own
text and a nested list steps in under its parent. Quotes and fenced code run behind a
rail down the left, drawn on *every* line including the wrapped ones.
* A fence tagged ``qr`` draws nothing of itself: its body is a URL, and the page shows
the app's scannable code for it (:func:`~meshterm.ui.qr.qr_text`).
* Emphasis, code, links and struck-out runs take the ``md.*`` styles, which — like every
style name here — mean something on both platforms (see :mod:`meshterm.ui.theme`). A
link shows its target after the text unless the text already says it; nothing here
@@ -248,6 +250,8 @@ def _block(node: SyntaxTreeNode, *, indent: int, depth: int) -> list[RenderableT
if kind == "blockquote":
quoted = Group(*_blocks(node.children, indent=0, depth=depth))
return [_pad(_Railed(Styled(quoted, "md.quote"), style="md.bullet"), indent)]
if kind == "fence" and node.info.strip() == "qr":
return [_pad(_qr(node.content.strip()), indent)]
if kind in ("fence", "code_block"):
code = Text(node.content.rstrip("\n"), style="md.code")
return [_pad(_Railed(code, style="md.rail"), indent)]
@@ -276,6 +280,29 @@ def _blocks(
return rendered
def _qr(data: str) -> RenderableType:
"""A ``qr`` fence: the URL inside it, drawn as the app's scannable code.
The code is generated as the page opens rather than pasted into the ``.md`` as
half-block art. Art cannot survive markdown — a row that happens to open on a light
module opens on a *space*, and every parser in the world eats it, shearing that row
one module to the left — and a code nobody can scan is worse than no code. Drawing it
live also means the link is written once, in the fence, and the code can never drift
from it.
Args:
data: The fence's body — the URL to encode.
Returns:
The code, from :func:`~meshterm.ui.qr.qr_text` — the same black-on-white widget
the share popups draw, so a QR looks the same everywhere in MeshTerm and reads
the same whatever palette the terminal is running.
"""
from .qr import qr_text
return qr_text(data)
def _pad(renderable: RenderableType, indent: int) -> RenderableType:
"""Hang ``renderable`` at ``indent`` cells (unchanged when it is flush)."""
if not indent:
+20
View File
@@ -191,6 +191,26 @@ def test_a_fenced_block_keeps_its_own_lines() -> None:
assert [line.rstrip() for line in lines] == [" │ one", " │ two"]
def test_a_qr_fence_draws_the_code_rather_than_the_url_inside_it() -> None:
"""The one fence that isn't quoted: its body is a link, and the page shows the code.
Drawn live from the fence, never pasted in as half-block art — art loses a row whose
first module is light, because that row starts with a space and markdown eats it.
"""
source = """```qr
https://example.com/x
```
"""
lines = [line for line in _lines(source) if line.strip()]
assert lines, "the fence rendered nothing"
assert not any("example.com" in line for line in lines), "the URL was printed as text"
assert all(set(line.strip()) <= set("█▀▄ ") for line in lines), lines
# Two of the three finder squares sit at either end of the code's first module row.
top = lines[0].strip()
assert top.startswith("█▀▀▀▀▀█") and top.endswith("█▀▀▀▀▀█"), top
def test_a_rule_runs_the_full_width_of_the_page() -> None:
"""``---`` is a page rule, not an indented one — it separates, so it spans."""
line = next(line for line in _lines("a\n\n---\n\nb\n", 40) if "─" in line)