{"record":{"id":"974f0ef841529477","repo":"koala73/worldmonitor","slug":"pagepath-renders-literal-markdown-emphasis-in-main","errorCode":null,"errorMessage":"${pagePath} renders literal markdown emphasis in <main>","messagePattern":"(.+?) renders literal markdown emphasis in <main>","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/build-crawlable-corpus.mjs","lineNumber":3572,"sourceCode":"function corpusVisibleText(html) {\n  return corpusMainHtml(html).replace(/<[^>]+>/g, ' ').replace(/\\s+/g, ' ').trim();\n}\n\nfunction intelBriefHtml(html) {\n  const match = corpusMainHtml(html).match(/<div\\b[^>]*\\bdata-intel-brief\\b[^>]*>([\\s\\S]*?)<\\/div>/i);\n  return match ? match[1] : null;\n}\n\n// #7738: prerendered country briefs were injected as escaped markdown, so\n// crawlers saw literal `**` and `WHAT THIS MEANS FOR NO`. Fail the build\n// when either artifact reaches <main>, including section titles that are\n// still plain text rather than <h*> tags.\nconst MEANS_FOR_ISO_RE = /^\\s*what this means for [a-z]{2}(?=\\s*(?::|$))/im;\n\nexport function assertCountryBriefPresentation({ pagePath, html, sources }) {\n  const main = corpusMainHtml(html);\n  if (main.includes('**')) {\n    throw new Error(`${pagePath} renders literal markdown emphasis in <main>`);\n  }\n  const brief = intelBriefHtml(html);\n  if (brief && sources !== undefined) {\n    // Check the rendered claim blocks as well as the input. A later formatter\n    // must not add an entity or change a citation after publish-time validation.\n    const claims = [...brief.matchAll(/<(p|li)\\b([^>]*)>([\\s\\S]*?)<\\/\\1>/gi)]\n      .filter((match) => !/\\bclass=\"source\"/.test(match[2]))\n      .map((match) => corpusVisibleText(match[3]).replace(/&(amp|lt|gt|quot|#39);/g,\n        (entity) => ({ '&amp;': '&', '&lt;': '<', '&gt;': '>', '&quot;': '\"', '&#39;': \"'\" })[entity]));\n    const gap = briefCitationGroundingGap({ text: claims.join('\\n'), sources });\n    if (gap) throw new Error(`${pagePath} brief has unsupported citation: ${gap}`);\n  }\n  const headingSource = brief ?? main;\n  const headingHits = [...headingSource.matchAll(/<h[1-6]\\b[^>]*>([\\s\\S]*?)<\\/h[1-6]>/gi)];\n  for (const hit of headingHits) {\n    const text = hit[1].replace(/<[^>]+>/g, ' ').replace(/\\s+/g, ' ').trim();\n    if (MEANS_FOR_ISO_RE.test(text)) {\n      throw new Error(`${pagePath} heading leaks ISO code: ${text}`);","sourceCodeStart":3554,"sourceCodeEnd":3590,"githubUrl":"https://github.com/koala73/worldmonitor/blob/7d06c8633d256c18e38133030bc3613976a96ec9/scripts/build-crawlable-corpus.mjs#L3554-L3590","documentation":"assertCountryBriefPresentation validates the published page: it extracts the <main> HTML and throws if it contains the literal sequence '**', meaning markdown emphasis was not converted or stripped before publishing. Publish rules require markdown emphasis to be stripped, so raw '**' in <main> indicates a leaky render pipeline that would show raw markdown syntax to readers and crawlers.","triggerScenarios":"Running assertCountryBriefPresentation({ pagePath, html, sources }) on HTML whose <main> contains '**'. Typically a brief text with markdown bold/italic passed through without the emphasis-stripping step, or a data string containing '**' interpolated as plain text.","commonSituations":"Brief content generated by a model containing markdown emphasis that bypassed the strip/render step; a new field rendered into the page without going through the shared emphasis-stripping helper; a legitimate '**' in the content (e.g. exponentiation or wildcard text).","solutions":["Run the brief content through the publish-time markdown-emphasis stripping helper before rendering","Locate the '**' occurrence in the page content and remove or properly convert it in the source data","Render the field through the same formatter used for validated brief fields instead of raw interpolation","If '**' is intentional content, rephrase or escape it to avoid the forbidden sequence"],"exampleFix":"// before\n<main><p>${brief.text}</p></main>          // renders \"**critical**\"\n// after\n<main><p>${stripMarkdownEmphasis(brief.text)}</p></main>  // renders \"critical\"","handlingStrategy":"validation","validationCode":"const main = corpusMainHtml(html);\nif (main.includes('**')) {\n  throw new Error(`${pagePath}: literal markdown emphasis leaked into <main>`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  assertCountryBriefPresentation({ pagePath, html, sources });\n} catch (err) {\n  if (err.message.includes('literal markdown emphasis')) {\n    console.error(`Raw markdown rendered for ${pagePath}; route content through stripMarkdownEmphasis()`);\n  }\n  throw err;\n}","preventionTips":["Route every brief field through the shared emphasis-stripping/formatter helper; never interpolate raw model output","Strip markdown emphasis at content-freeze time so unformatted text cannot enter the pipeline later","Lint generated content for '**' and other markdown syntax before rendering","If content legitimately needs '**', escape or rephrase it at authoring time"],"tags":["build","markdown","presentation"],"backgroundTag":"invalid-argument-format","analyzedSha":"7d06c8633d256c18e38133030bc3613976a96ec9","analyzedAt":"2026-09-15T16:44:39.439Z","contentChangedAt":"2026-09-15T16:44:39.439Z","schemaVersion":2},"datasetVersion":"2026-09-15T18:17:12.389Z"}