Skip to content

Commit 0f1fcb7

Browse files
committed
fix(memory-wiki): strip fenced code blocks before wikilink extraction (fixes #97945)
Fenced code blocks and inline code spans containing [[...]] patterns (e.g. Scala generics Future[Option[User]], bash [[ "" == "y" ]]) were falsely reported as broken wikilink targets. Strip them from the searchable text before running the wikilink regex. This reopens and implements the validated fix from #70986.
1 parent 455f813 commit 0f1fcb7

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

extensions/memory-wiki/src/markdown.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ const RELATED_BLOCK_PATTERN = new RegExp(
116116
`${WIKI_RELATED_START_MARKER}[\\s\\S]*?${WIKI_RELATED_END_MARKER}`,
117117
"g",
118118
);
119+
/** Matches fenced code blocks (```...```) including the language tag. */
120+
const FENCED_CODE_BLOCK_PATTERN = /```[\s\S]*?```/g;
121+
/** Matches inline code spans (`...`). */
122+
const INLINE_CODE_PATTERN = /`[^`]+`/g;
119123
const MAX_WIKI_SEGMENT_BYTES = 240;
120124
const MAX_WIKI_FILENAME_COMPONENT_BYTES = 255;
121125
const FS_SAFE_PINNED_WRITE_TEMP_SUFFIX = ".00000000-0000-4000-8000-000000000000.fallback.tmp";
@@ -387,7 +391,14 @@ function normalizeMarkdownLinkTarget(sourceRelativePath: string, target: string)
387391
}
388392

389393
function extractWikiLinks(markdown: string, sourceRelativePath: string): string[] {
390-
const searchable = markdown.replace(RELATED_BLOCK_PATTERN, "");
394+
// Strip fenced code blocks and inline code spans before searching for
395+
// wikilinks, so [[...]] patterns inside code (e.g. Scala generics like
396+
// Future[Option[User]], bash [[ "$x" == "y" ]]) are not falsely
397+
// reported as broken wikilink targets. (#97945)
398+
const searchable = markdown
399+
.replace(RELATED_BLOCK_PATTERN, "")
400+
.replace(FENCED_CODE_BLOCK_PATTERN, "")
401+
.replace(INLINE_CODE_PATTERN, "");
391402
const links: string[] = [];
392403
for (const match of searchable.matchAll(OBSIDIAN_LINK_PATTERN)) {
393404
const target = match[1]?.trim();

0 commit comments

Comments
 (0)