Skip to content

Support Obsidian wikilink embeds (![[target]]) - #828

Closed
ChrisJr404 wants to merge 1 commit into
kivikakk:mainfrom
ChrisJr404:wikilink-embeds
Closed

Support Obsidian wikilink embeds (![[target]])#828
ChrisJr404 wants to merge 1 commit into
kivikakk:mainfrom
ChrisJr404:wikilink-embeds

Conversation

@ChrisJr404

Copy link
Copy Markdown

Closes #535.

Wikilinks written with a leading ! (Obsidian's embed syntax, ![[target]]) previously weren't recognised: the ! was consumed as an ordinary image marker, so no wikilink node was produced. This adds support for parsing them as embeds when a wikilinks extension is enabled.

Following the discussion on #535, the parsing surface is the important part — NodeWikiLink now carries an embed: bool so downstream consumers can tell embeds apart and decide how to handle the target (image, transcluded note, canvas, etc.). Since the issue is specifically about image embeds and you pointed at image_url_rewriter, embeds also render as images out of the box.

What's included

  • Parsing: ![[target]] is parsed as a wikilink with embed = true (both wikilinks_title_after_pipe and wikilinks_title_before_pipe modes). Plain [[target]] keeps embed = false. The source position includes the leading !. If the ![[… doesn't form a valid wikilink, it falls back to the previous image-marker behaviour.
  • NodeWikiLink::embed: new field, defaults to false.
  • HTML: embeds render as <img src="…" data-wikilink="true" alt="…" />, with the label as alt text and image_url_rewriter applied to the URL (mirroring render_image). Dangerous URLs are sanitised just like images. Non-embed wikilinks are byte-for-byte unchanged.
  • XML: embeds get an embed="true" attribute.
  • CommonMark round-trip: embeds are re-emitted with the leading !.
  • Docs: the wikilinks_title_after_pipe option gains a note + doctest for embeds.

Tests

Added to src/tests/wikilinks.rs: HTML rendering for both pipe modes, image_url_rewriter interaction, URL sanitisation, the XML embed attribute, source positions, and regressions confirming that [[target]] still renders as a link and that ![[…]] is inert without the extension. Full suite (cargo test) and cargo fmt --check pass; no new clippy warnings.

A wikilink prefixed with `!` is now parsed as an embed when a wikilinks
extension is enabled, matching Obsidian's `![[target]]` syntax. Previously
the leading `!` was treated as an ordinary image marker, so these never
produced a wikilink node.

`NodeWikiLink` gains an `embed` field. Embeds render as `<img>` in HTML
output (honouring `image_url_rewriter`, with the label used as alt text),
are marked with `embed="true"` in XML output, and round-trip through the
CommonMark formatter. Ordinary `[[target]]` wikilinks are unaffected.

Closes kivikakk#535.
@kivikakk

Copy link
Copy Markdown
Owner

@kivikakk kivikakk closed this Aug 18, 2026
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.

Obsidian wikilink images ![[image.jpg]]

2 participants