Skip to content

Commit aeceb4f

Browse files
committed
fix(memory-wiki): require fence close whitespace
1 parent 16b8d36 commit aeceb4f

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

extensions/memory-wiki/src/markdown.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ describe("toWikiPageSummary", () => {
7474
"fi",
7575
"```",
7676
"",
77+
"```md",
78+
"```ts",
79+
"const nestedFenceFake = '[[nested-fence-fake]]';",
80+
"```",
81+
"",
82+
"After the code block, links count again: [[after-code]].",
83+
"",
7784
"```scala",
7885
"val maybeUser: Future[Option[User]] = loadUser()",
7986
"```",
@@ -82,7 +89,7 @@ describe("toWikiPageSummary", () => {
8289
}),
8390
});
8491

85-
expect(summary?.linkTargets).toEqual(["real-target", "sources/guide.md"]);
92+
expect(summary?.linkTargets).toEqual(["real-target", "after-code", "sources/guide.md"]);
8693
});
8794

8895
it("marks raw and generated source body metadata", () => {

extensions/memory-wiki/src/markdown.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const RELATED_BLOCK_PATTERN = new RegExp(
116116
`${WIKI_RELATED_START_MARKER}[\\s\\S]*?${WIKI_RELATED_END_MARKER}`,
117117
"g",
118118
);
119-
const FENCED_CODE_START_PATTERN = /^(?: {0,3})(`{3,}|~{3,})/;
119+
const FENCED_CODE_LINE_PATTERN = /^(?: {0,3})(`{3,}|~{3,})(.*)$/;
120120
const MAX_WIKI_SEGMENT_BYTES = 240;
121121
const MAX_WIKI_FILENAME_COMPONENT_BYTES = 255;
122122
const FS_SAFE_PINNED_WRITE_TEMP_SUFFIX = ".00000000-0000-4000-8000-000000000000.fallback.tmp";
@@ -420,10 +420,15 @@ function maskMarkdownCode(markdown: string): string {
420420
let fence: { marker: "`" | "~"; length: number } | null = null;
421421

422422
for (const line of lines) {
423-
const fenceMatch = FENCED_CODE_START_PATTERN.exec(line);
423+
const fenceMatch = FENCED_CODE_LINE_PATTERN.exec(line);
424424
const fenceDelimiter = fenceMatch?.[1];
425+
const fenceRest = fenceMatch?.[2] ?? "";
425426
if (fence) {
426-
if (fenceDelimiter?.startsWith(fence.marker) && fenceDelimiter.length >= fence.length) {
427+
if (
428+
fenceDelimiter?.startsWith(fence.marker) &&
429+
fenceDelimiter.length >= fence.length &&
430+
fenceRest.trim().length === 0
431+
) {
427432
fence = null;
428433
}
429434
maskedLines.push("");

0 commit comments

Comments
 (0)