Support Obsidian wikilink embeds (![[target]]) - #828
Closed
ChrisJr404 wants to merge 1 commit into
Closed
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 —
NodeWikiLinknow carries anembed: boolso 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 atimage_url_rewriter, embeds also render as images out of the box.What's included
![[target]]is parsed as a wikilink withembed = true(bothwikilinks_title_after_pipeandwikilinks_title_before_pipemodes). Plain[[target]]keepsembed = 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 tofalse.<img src="…" data-wikilink="true" alt="…" />, with the label as alt text andimage_url_rewriterapplied to the URL (mirroringrender_image). Dangerous URLs are sanitised just like images. Non-embed wikilinks are byte-for-byte unchanged.embed="true"attribute.!.wikilinks_title_after_pipeoption gains a note + doctest for embeds.Tests
Added to
src/tests/wikilinks.rs: HTML rendering for both pipe modes,image_url_rewriterinteraction, URL sanitisation, the XMLembedattribute, source positions, and regressions confirming that[[target]]still renders as a link and that![[…]]is inert without the extension. Full suite (cargo test) andcargo fmt --checkpass; no new clippy warnings.