Skip to content

feat(ui): add [[Title]] wiki-link rendering and disambiguation dialog#1120

Merged
perber merged 6 commits into
mainfrom
feature/wiki-links-frontend
Jun 4, 2026
Merged

feat(ui): add [[Title]] wiki-link rendering and disambiguation dialog#1120
perber merged 6 commits into
mainfrom
feature/wiki-links-frontend

Conversation

@perber

@perber perber commented Jun 4, 2026

Copy link
Copy Markdown
Owner

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.

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.
Copilot AI review requested due to automatic review settings June 4, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 getPagesByTitle to the tree store to resolve [[Title]] references against the loaded page tree.
  • Introduced preprocessWikilinks to convert wiki-link syntax into Markdown links (including special wikilink-*: 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.

Comment thread ui/leafwiki-ui/src/features/preview/MarkdownPreview.tsx
Comment thread ui/leafwiki-ui/src/features/preview/MarkdownLink.tsx
Comment thread ui/leafwiki-ui/src/features/preview/MarkdownLink.tsx Outdated
Comment thread ui/leafwiki-ui/src/features/wikilinks/WikiLinkDisambiguationDialog.tsx Outdated
Comment thread ui/leafwiki-ui/src/lib/preprocessWikilinks.ts Outdated
perber added 5 commits June 4, 2026 16:11
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.
@perber
perber merged commit 495ca3e into main Jun 4, 2026
9 checks passed
@perber
perber deleted the feature/wiki-links-frontend branch June 4, 2026 14:59
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.

2 participants