link
rpic extension. link makes an object a hyperlink: its SVG shape group
is wrapped in <a href="…">, so clicking the shape — label included —
navigates to the URL. No JavaScript, no host wiring: it’s native SVG, and it
works wherever the SVG is a real document (inline-embedded, <img src>, or
opened directly).
Two forms write to the same hook — and since this page is a host document, these are live links (click them!):
.PS
box "rpic.dev" fit link "https://rpic.dev" # inline, at creation
A: circle "GitHub" rad 0.42 at last box + (1.6, 0)
arrow from last box.e to A.w
link A "https://github.com/milkway/rpic-lang" # statement: by label
.PEThe statement form uses pic’s native references — labels and ordinals — so it also reaches shapes drawn inside macros (circuit elements!), and lets link lines cluster at the end of a picture.
Rules
- SVG-only. PNG and PDF render the identical picture, just without the link (the raster pipeline flattens the anchor to a plain group).
- Validated, not raw. The URL must be non-empty, free of whitespace and
control characters (percent-encode them), and must not use a
script-executing scheme (
javascript:,vbscript:,data:) — a host that renders untrusted pictures inline must not gain an XSS surface. Relative URLs,#fragmentsandmailto:all pass. - Reapplying replaces — the last
linkwins. (Unlikeclass, URLs don’t compose.) - The anchor wraps outside the
<g id="sN">group: the stable ids and theanimate/GSAP contract are untouched, andclass+linkcompose on the same shape. - The anchor carries
class="rpic-link", so the commona:not([class])prose pattern in host pages (underline, link colour) never restyles the picture’s labels — and.rpic-linkis your styling hook when you do want a hover affordance. - The compile bundle’s
objectsentries carry a"link"key when set, so editors and players can surface it. linkis contextual:link = 2is still an assignment andbox wid linkstill reads the variable. Unused, the output is byte-for-byte classic.- Blocks are not supported yet — link the inner objects instead. A point label has no drawn shape, so linking it is an error.
An open object (a line or arc) is only as clickable as its stroke is
wide. For a generous hit area, link a filled shape near it, or thicken
the stroke (thick 1.6).
Cross-linking a diagram
Fragments (#…) and relative URLs pass validation, so a picture can link
into its own page — a table of contents that is also the system diagram:
.PS
B1: box "Rules" fit link "#rules"
arrow
B2: box "Cross-linking" fit link "#cross-linking-a-diagram"
.PEDesign notes: docs/extensions.md.