diff --git a/tools/doc/allhtml.mjs b/tools/doc/allhtml.mjs
index db1e724c0aa2f9..f37dfdd93c1a39 100644
--- a/tools/doc/allhtml.mjs
+++ b/tools/doc/allhtml.mjs
@@ -44,7 +44,8 @@ for (const link of toc.match(//g)) {
apicontent += '' + data.slice(match.index + match[0].length)
.replace(/[\s\S]*/, '')
// Prefix all in-page anchor marks with module name
- .replace(/ {
+ .replace(/ {
+ if (anchor !== id) throw new Error(`Mark does not match: ${anchor} should match ${id}`);
return `