feat(ui): add [[Title]] wiki-link rendering and disambiguation dialog#1120
Merged
Conversation
Preprocesses [[Title]] and [[Title|Alias]] syntax before markdown rendering. Single title matches resolve directly to the target page. Missing pages show as red broken links with a create-page prompt. Ambiguous titles (N>1 matches) show a disambiguation dialog so the user can pick the intended page. [[Folder/Title]] is treated as a direct path hint.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces MediaWiki-style [[Title]] / [[Title|Alias]] wiki-link rendering in the UI by preprocessing content before it’s fed into the Markdown renderer, then handling unresolved and ambiguous links with custom UI flows.
Changes:
- Added
getPagesByTitleto the tree store to resolve[[Title]]references against the loaded page tree. - Introduced
preprocessWikilinksto convert wiki-link syntax into Markdown links (including specialwikilink-*:schemes for not-found/ambiguous cases). - Added and registered a new disambiguation dialog, and extended the Markdown link renderer to open dialogs for ambiguous/missing wiki-links.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/leafwiki-ui/src/stores/tree.ts | Adds title-based lookup helper for resolving wiki-links against the page tree. |
| ui/leafwiki-ui/src/lib/registries/index.tsx | Registers the new wiki-link disambiguation dialog type. |
| ui/leafwiki-ui/src/lib/preprocessWikilinks.ts | New preprocessing step converting [[...]] syntax into Markdown links with resolution rules. |
| ui/leafwiki-ui/src/features/wikilinks/WikiLinkDisambiguationDialog.tsx | New dialog UI for selecting a page when a title resolves to multiple matches. |
| ui/leafwiki-ui/src/features/preview/MarkdownPreview.tsx | Integrates wiki-link preprocessing into preview rendering and re-resolves on tree reload. |
| ui/leafwiki-ui/src/features/preview/MarkdownLink.tsx | Handles wikilink-notfound: and wikilink-ambiguous: links by opening dialogs / showing broken-link UI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
A1: Add wikilink-notfound/ambiguous to rehypeSanitize protocol allowlist
so those hrefs are no longer stripped and the disambiguation/create-page
flows actually work.
A2: Protect fenced code blocks and inline code spans from wiki-link regex
substitution using placeholder extraction before processing.
A3: Slugify the wiki-link title via /api/pages/slug-suggestion before
opening the create-page dialog, so "Project Plan" doesn't produce an
invalid path with spaces.
A4: Pass byId directly into the preprocessWikilinks call instead of using
a getPagesByTitle selector reference, giving useMemo a clean explicit
dependency and removing the eslint-disable workaround.
- preprocessWikilinks: replace control-char placeholder (\x00) with a split()-based approach that keeps code spans at odd array indices, fixing the ESLint no-control-regex CI failure. Add per-call title cache to avoid O(numLinks × numPages) scans for repeated titles. - MarkdownLink: guard both decodeURIComponent calls with try/catch via safeDecodeURIComponent so a hand-authored malformed wikilink-*: href cannot crash the Markdown renderer. - WikiLinkDisambiguationDialog: derive matches directly from the Zustand selector instead of calling a stable function ref, so the list re-renders when byId changes (e.g. after a tree reload).
Installs Vitest, jsdom, and @testing-library/* as dev dependencies. Adds a separate vitest.config.ts so the Vite build config stays clean. Tests added: - preprocessWikilinks.test.ts: 18 tests covering single/no/ambiguous matches, alias syntax, path hints, fenced + inline code protection, title deduplication caching, and edge cases. - tree.test.ts: 4 tests for getPagesByTitle store selector (case- insensitive lookup, multiple matches, empty tree). Adds npm test / test:watch / test:coverage scripts to package.json. Adds a new test-frontend job to frontend.yml that runs on every PR.
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.
Preprocesses [[Title]] and [[Title|Alias]] syntax before markdown rendering. Single title matches resolve directly to the target page. Missing pages show as red broken links with a create-page prompt. Ambiguous titles (N>1 matches) show a disambiguation dialog so the user can pick the intended page. [[Folder/Title]] is treated as a direct path hint.