From 75eafeff84c4120d205ca292e47c0c7d55ca18c1 Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Tue, 19 May 2026 22:25:09 +0200 Subject: [PATCH] infra(sync-motoko): fix bare numeric-prefix links and em-dashes in postprocessor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two postprocessor bugs that caused PR #262 to produce broken links and em-dashes in synced Motoko docs: 1. Link regex only matched `./` and `../` relative links. Bare numeric-prefix links like `10-contextual-dot.md` (used by upstream in v1.8.0) were never passed to `rewriteLink` and remained broken. The updated regex also matches `\d+-name.md` patterns; `rewriteLink` already strips numeric prefixes and resolves slugs at line 214. 2. Em-dashes (` — `, banned per style guide) were not replaced during sync. Added a prose-only replacement pass (` — ` → `: `) after the link rewrites, with a fenced-code-block split so code comments like `// ERROR — not static` are preserved verbatim. Both fixes are defensive: they become no-ops once upstream PR caffeinelabs/motoko#6132 (§5 numeric prefixes, §8 em-dashes) merges. Co-Authored-By: Claude Sonnet 4.6 --- scripts/postprocess-motoko.mjs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/postprocess-motoko.mjs b/scripts/postprocess-motoko.mjs index 93af468..c40ec68 100644 --- a/scripts/postprocess-motoko.mjs +++ b/scripts/postprocess-motoko.mjs @@ -357,8 +357,8 @@ function processFile(filePath) { } } - // Rewrite relative links (./ and ../ paths) - const linkRe = /\]\((\.[^)#]*?)(#[^)]+)?\)/g; + // Rewrite relative links (./ and ../ paths, plus bare numeric-prefix .md links like 10-name.md) + const linkRe = /\]\((\.[^)#]*?|\d+[^)#/\s]*\.md)(#[^)]+)?\)/g; content = content.replace(linkRe, (match, path, anchor) => { anchor = anchor || ''; const newUrl = rewriteLink(path, anchor, relPath); @@ -392,6 +392,15 @@ function processFile(filePath) { return match; }); + // Replace em-dashes in prose (banned per style guide). Skip fenced code blocks. + { + const parts = content.split(/(^```[\s\S]*?^```)/m); + const fixed = parts + .map((part, i) => (i % 2 === 0 ? part.replace(/ — /g, ': ') : part)) + .join(''); + if (fixed !== content) { content = fixed; changed = true; } + } + if (changed) writeFileSync(filePath, content); return changed; }