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.
This commit is contained in:
xarmian
2026-04-17 04:04:57 +00:00
parent de21b1199d
commit 922cb26e1d
+15
View File
@@ -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);