From d1a5ea397510150ea8a77c7a5e75a04a1f2d211e Mon Sep 17 00:00:00 2001 From: xarmian Date: Fri, 17 Apr 2026 03:44:41 +0000 Subject: [PATCH] fix: robust wiki-link round-trip and navigable popover (BUG-586 follow-ups) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to the BUG-586 fix that surfaced several edge cases under real-world use. Covers three related improvements to the wiki-link experience in the editor. Reference-based wiki-link storage Previously `[Title](/url)` round-tripped to `[[Title]]`. That form broke for titles containing `[`, `]`, `/`, or `|`. Storage now uses the item's opaque ref (e.g. `[[BUG-586]]`, or `[[BUG-586|Custom]]` when the visible text differs from the item's current title). `wikiLinksToMarkdown` accepts three forms in preference order: ref-only, ref-with-display-override, and legacy title lookup. Titles can now contain any characters and links survive renames. Escape-aware parsing Both `markdownToWikiLinks` and `wikiLinksToMarkdown` now recognize `\.` escape sequences inside their capture groups. tiptap-markdown emits `\[`, `\]`, `\\` in link text when the text contains literal brackets, so the prior regexes (`[^\]]+`) terminated prematurely and missed valid links. Helper functions escape/unescape the markdown link-text layer and the wiki-link body layer separately so `]`, `|`, and `\` can appear in display-override text. Leave unresolved [[X]] untouched The `[[…]]` regex is greedy and can match spans that were never intended as wiki-links — notably `[[` sequences inside another markdown link's text. On miss, the function now returns the original match verbatim instead of emitting `[…](broken)`, which previously hijacked surrounding content and accumulated corruption on each save cycle. Broken items heal themselves on the next auto-save. Picker: show ref + align URL with the route The `[[` picker now lists the ref badge next to the title and keys `{#each}` by `doc.id` so duplicate titles don't collide. `execLink` now reads `page.params.username`/`page.params.workspace` from the live route (previously `workspaceStore.current`, which could be empty), so the inserted `href` matches the URL shape that the round-trip expects. Clickable link popover The popover's URL label is now a real ``. Plain click → `goto()` for internal paths, full navigation for external. Ctrl / Cmd / middle-click pass through to the browser so "new tab" and "copy link" work naturally. `onmousedown.stopPropagation` keeps the outer popover's focus-trap from swallowing the click. --- web/src/lib/components/editor/Editor.svelte | 44 ++++- .../editor/EditorLinkPopover.svelte | 46 ++++- web/src/lib/utils/markdown.ts | 167 +++++++++++++++--- 3 files changed, 220 insertions(+), 37 deletions(-) diff --git a/web/src/lib/components/editor/Editor.svelte b/web/src/lib/components/editor/Editor.svelte index a1615fe1..9f6b6bbf 100644 --- a/web/src/lib/components/editor/Editor.svelte +++ b/web/src/lib/components/editor/Editor.svelte @@ -1,5 +1,6 @@