Skip to content

Add wikilink rendering extension#222

Open
soreavis wants to merge 1 commit into
sbarex:mainfrom
soreavis:feature/wikilinks
Open

Add wikilink rendering extension#222
soreavis wants to merge 1 commit into
sbarex:mainfrom
soreavis:feature/wikilinks

Conversation

@soreavis

Copy link
Copy Markdown
Contributor

Adds support for [[wikilinks]] (closes #63). cmark-gfm reserves [ for its own link parser, so this is a post-process cmark-extra extension (wikilink.c) modeled on cmark-gfm's own autolink — it splits text nodes after parsing, leaving the cmark engine untouched.

[[Page Name]] and [[Target|Display]] are rewritten into styled links:

See [[Getting Started]] and the [[Reference|API reference]].

<p>See <a class="wikilink" href="Getting%20Started">Getting Started</a> and the <a class="wikilink" href="Reference">API reference</a>.</p>

Behaviour

  • Off by default. The inner text must be non-empty, alone between the brackets, and free of [/] — so ordinary text, malformed/nested brackets, code spans, and existing Markdown links are left untouched.
  • [[Target|Display]] splits on the first | (target → href, the rest → label); [[Target|]] falls back to the target as the label.
  • Leading/trailing whitespace in the target and label is trimmed.
  • Security: the target is houdini-escaped into the href and dangerous URLs (javascript: …) are dropped in safe mode — identical to how cmark renders native links; labels are HTML-escaped. (Validated under AddressSanitizer + leaks on adversarial input: no over-reads, use-after-free, or leaks.)
  • default.css styles .wikilink (light #8250df / dark #ab7df8), distinct from regular links.

How it's exposed

  • Preferences UI — a new "Wikilinks" checkbox in the Extensions grid, wired like the other extension toggles.
  • CLI — a --wikilink on|off option.
  • Settings — a wikilinkExtension flag (Codable + app-group defaults), defaulting to off.

Examples

  • Adds examples/test-wikilink.md (basic, aliased, paths, multiple-per-line, plus the edge cases: empty/whitespace markers, malformed brackets, code spans, Markdown-inside).
  • Enriches examples/test1.md — the file shown in the Settings live preview — with a "Wikilink extension" section and its TOC entry.

Changed files

  • cmark-extra/extensions/wikilink.{c,h}, extra-extensions.c — the extension and its registration
  • QLMarkdown/Settings.swift, Settings+render.swift, Settings+ext.swift — the flag and render wiring
  • qlmarkdown_cli/qlmarkdown_cli.swift — the CLI option
  • QLMarkdown/ViewController.swift, Base.lproj/Main.storyboard — the Preferences checkbox
  • Resources/default.css — the .wikilink style (light & dark)
  • examples/test-wikilink.md, examples/test1.md — examples

Wikilinks rendered in the settings preview

Closes #63.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Syntax highlighting for wikilinks?

1 participant