From 922cb26e1d056415310b8eaba2d8fdc4ae186e5b Mon Sep 17 00:00:00 2001 From: xarmian Date: Fri, 17 Apr 2026 04:04:57 +0000 Subject: [PATCH] fix: preserve legacy [[coll/Title]] links whose titles contain `|` Follow-up to the previous commit: the full-body title lookup handled the plain-title case, but collection-qualified legacy links like `[[tasks/A|B]]` (where the item's real title is "A|B" in "tasks") were still split on the pipe before the collection/title resolution ran, so the lookup was attempted for title "A" and the link rendered as plain text. Add a full-body collection-qualified lookup alongside the full-body title lookup, both before the `key|display` split. --- web/src/lib/utils/markdown.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/web/src/lib/utils/markdown.ts b/web/src/lib/utils/markdown.ts index 019a8c93..615b2b88 100644 --- a/web/src/lib/utils/markdown.ts +++ b/web/src/lib/utils/markdown.ts @@ -102,6 +102,21 @@ export function wikiLinksToMarkdown(content: string, items: Item[], workspaceSlu return `[${escapeMarkdownLinkText(fullTitleItem.title)}](${prefix}/${fullTitleItem.collection_slug}/${itemUrlId(fullTitleItem)})`; } + // Also try the collection-qualified legacy form on the full body, + // before the pipe split. Handles "[[tasks/A|B]]" where the actual + // title is literally "A|B" in the "tasks" collection. + if (fullBody.includes('/')) { + const [qualColl, ...qualRest] = fullBody.split('/'); + const qualTitle = qualRest.join('/'); + const qualItem = items.find(i => + i.title.toLowerCase() === qualTitle.toLowerCase() && + i.collection_slug === qualColl + ); + if (qualItem && qualItem.collection_slug) { + return `[${escapeMarkdownLinkText(qualItem.title)}](${prefix}/${qualItem.collection_slug}/${itemUrlId(qualItem)})`; + } + } + // Split optional display override on the FIRST unescaped pipe. const { key: rawKey, displayOverride: rawDisplay } = splitWikiBody(body); const key = unescapeWikiBody(rawKey);