From 0dfbd08db6d7c7bd349c93360d5c791ff6700962 Mon Sep 17 00:00:00 2001 From: me Date: Mon, 3 Aug 2026 02:13:10 +0200 Subject: [PATCH] feat: add Obsidian-style embeds and wiki-link display text --- README.md | 2 + docs/embeds.md | 86 ++++++++++++++++ package.json | 2 +- src/parser/embeds.ts | 135 +++++++++++++++++++++++++ src/parser/markdown.ts | 2 + src/parser/wiki-links.ts | 9 +- static/markdown.css | 27 +++++ tests/rendering/markdown-additional.md | 38 ++++++- tests/unit/embeds.ts | 116 +++++++++++++++++++++ tests/unit/wiki-links.ts | 34 +++++++ 10 files changed, 446 insertions(+), 5 deletions(-) create mode 100644 docs/embeds.md create mode 100644 src/parser/embeds.ts create mode 100644 tests/unit/embeds.ts create mode 100644 tests/unit/wiki-links.ts diff --git a/README.md b/README.md index 2955ab2a..cac4b1e5 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ issue](https://github.com/jannis-baum/vivify/issues/new/choose) or - links to other files: [relative links like in GitHub](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#relative-links) as well as absolute file links +- [Obsidian-style embeds](docs/embeds.md) (`![[file]]`) and wiki-links + (`[[file]]`) - [add styles, classes, ids or other attributes directly from Markdown](https://github.com/arve0/markdown-it-attrs?tab=readme-ov-file#examples) - table of contents with `[[toc]]` diff --git a/docs/embeds.md b/docs/embeds.md new file mode 100644 index 00000000..7993b612 --- /dev/null +++ b/docs/embeds.md @@ -0,0 +1,86 @@ +# Embeds and wiki-links + +Vivify supports [Obsidian-style](https://help.obsidian.md/) wiki-links and +embeds in addition to standard Markdown links. + +## Wiki-links + +With the syntax `[[page]]` you link to another file. If the link target has no +file extension, a `.md` extension is assumed, matching Obsidian's behaviour: + +```md +See [[other-note]], or [[other-note.md]] if you want an explicit extension. +``` + +To use custom link text, append a pipe and the desired text: + +```md +[[other-note.md|My Other Note]] +[[other-note|My Other Note]] +``` + +The left side is used for the link `href` (with `.md` appended when no +extension is present), and the right side is shown as the link's text. + +## Embeds + +Prefixing a wiki-link with `!` turns it into an inline **embed** instead of a +link: + +```md +![[image.jpg]] +``` + +The path is resolved relative to the document you are viewing, just like regular +relative links and images. Which HTML element is generated depends on the file +type, detected from the file extension: + +- **Images** (`jpg`, `jpeg`, `png`, `gif`, `webp`, `svg`, `bmp`, `ico`, `avif`) + are embedded with an `` element, just like a standard + `![](image.jpg)` reference. +- **PDFs** (`pdf`) are embedded in an ``; + } + + // Video: