{"record":{"id":"4dc6d76adedfef02","repo":"prettier/prettier","slug":"unexpected-markdown-node-type-json-stringify-no","errorCode":null,"errorMessage":"Unexpected Markdown node type: ${JSON.stringify(node.type)}.","messagePattern":"Unexpected Markdown node type: (.+?)\\.","errorType":"exception","errorClass":"UnexpectedNodeError","httpStatus":null,"severity":"error","filePath":"src/language-markdown/print/mdast.js","lineNumber":424,"sourceCode":"        \"$$\",\n        node.meta ? \" \" + node.meta : \"\",\n        hardline,\n        node.value ? [replaceEndOfLine(node.value, hardline), hardline] : \"\",\n        \"$$\",\n      ];\n    case \"inlineMath\":\n      // remark-math trims content but we don't want to remove whitespaces\n      // since it's very possible that it's recognized as math accidentally\n      return options.originalText.slice(locStart(node), locEnd(node));\n    case \"text\":\n      return replaceEndOfLine(node.value, hardline);\n\n    case \"frontMatter\": // Handled in core\n    case \"tableRow\": // handled in \"table\"\n    case \"listItem\": // handled in \"list\"\n    default:\n      /* c8 ignore next */\n      throw new UnexpectedNodeError(node, \"Markdown\");\n  }\n}\n\nfunction printRoot(path, options, print) {\n  /** @typedef {{ index: number, offset: number }} IgnorePosition */\n  /** @type {Array<{start: IgnorePosition, end: IgnorePosition}>} */\n  const ignoreRanges = [];\n\n  /** @type {IgnorePosition | null} */\n  let ignoreStart = null;\n\n  const { children } = path.node;\n  for (const [index, childNode] of children.entries()) {\n    switch (isPrettierIgnore(childNode)) {\n      case \"start\":\n        if (ignoreStart === null) {\n          ignoreStart = { index, offset: childNode.position.end.offset };\n        }","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/prettier/prettier/blob/903845c7d16ce66dedd9d5ab4b858d233f48341a/src/language-markdown/print/mdast.js#L406-L442","documentation":"Thrown by the markdown (mdast) printer's switch default (src/language-markdown/print/mdast.js:424) via `UnexpectedNodeError(node, \"Markdown\")`. It also covers `frontMatter` (handled in core), `tableRow` (handled in `table`), and `listItem` (handled in `list`). Any mdast node type not in the handled list raises this. Marked `/* c8 ignore next */`.","triggerScenarios":"A markdown AST (mdast) node whose `type` is not recognized — e.g. a remark plugin injecting custom node types (callouts, directives, math variants) without a corresponding Prettier printer case, or a hand-built mdast tree passed to the printer.","commonSituations":"Using remark/mdx plugins that add custom mdast node types (remark-directive, remark-callouts) without a Prettier plugin that prints them; remark version producing node names newer Prettier doesn't know.","solutions":["Check `error.node.type` to identify the unrecognized markdown node.","Add a Prettier plugin/printer case that handles the custom mdast node type, or remove the remark plugin that emits it.","Align remark and Prettier versions so node vocabularies match.","Strip/transform custom nodes before formatting if you don't need them printed."],"exampleFix":"// before\n// remark plugin injects { type: 'callout', ... } which printer lacks\nawait prettier.format(md, { parser: 'markdown', plugins: [remarkCallouts] });\n\n// after — drop the plugin or add a printer for 'callout'\nawait prettier.format(md, { parser: 'markdown' });","handlingStrategy":"try-catch","validationCode":"const MDAST_OK = new Set(['root','paragraph','heading','code','html','list','listItem','blockquote','thematicBreak','link','linkReference','image','imageReference','footnoteDefinition','footnoteReference','table','tableCell','text','emphasis','strong','delete','inlineCode','break','jsx','esComment','math','inlineMath','frontMatter','tableRow']);\nfunction findUnknownMdast(ast) {\n  let bad;\n  walk(ast, (n) => { if (n.type && !MDAST_OK.has(n.type)) bad = n.type; });\n  return bad;\n}","typeGuard":"function isKnownMdastType(type) {\n  return ['root','paragraph','heading','code','html','list','listItem','blockquote','thematicBreak','link','linkReference','image','imageReference','table','text','emphasis','strong','inlineCode','break','jsx','esComment','math','inlineMath'].includes(type);\n}","tryCatchPattern":"try {\n  await prettier.format(md, { parser: 'markdown', plugins });\n} catch (e) {\n  if (/Unexpected Markdown node type/.test(e.message)) {\n    return prettier.format(md, { parser: 'markdown' }); // drop custom remark plugins\n  }\n  throw e;\n}","preventionTips":["Pair custom remark plugins with a Prettier printer for their node types.","Don't mix remark plugin versions that rename mdast nodes.","Test markdown formatting with the plugins you ship."],"tags":["markdown","mdast","ast","printer","plugin-incompatibility"],"backgroundTag":null,"analyzedSha":"903845c7d16ce66dedd9d5ab4b858d233f48341a","analyzedAt":"2026-08-09T13:56:28.558Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}