{"record":{"id":"7c2bce338b69047c","repo":"d2lang/d2","slug":"native-markdown-svg-does-not-support-html-element","errorCode":null,"errorMessage":"native Markdown SVG does not support HTML element <%s>","messagePattern":"native Markdown SVG does not support HTML element <(.+?)>","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/textmeasure/markdown_svg.go","lineNumber":1923,"sourceCode":"func nodeAttr(n *html.Node, name string) string {\n\tfor _, attr := range n.Attr {\n\t\tif attr.Key == name {\n\t\t\treturn attr.Val\n\t\t}\n\t}\n\treturn \"\"\n}\n\nfunc validateMarkdownSVGNodes(n *html.Node) error {\n\tif n.Type == html.ElementNode {\n\t\tswitch n.Data {\n\t\tcase \"html\", \"head\", \"body\",\n\t\t\t\"p\", \"h1\", \"h2\", \"h3\", \"h4\", \"h5\", \"h6\",\n\t\t\t\"blockquote\", \"ul\", \"ol\", \"li\", \"pre\", \"code\",\n\t\t\t\"em\", \"b\", \"strong\", \"del\", \"s\", \"strike\", \"a\", \"br\", \"hr\", \"img\",\n\t\t\t\"table\", \"thead\", \"tbody\", \"tfoot\", \"tr\", \"td\", \"th\":\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"native Markdown SVG does not support HTML element <%s>\", n.Data)\n\t\t}\n\t}\n\tfor child := n.FirstChild; child != nil; child = child.NextSibling {\n\t\tif err := validateMarkdownSVGNodes(child); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc goMax(a, b float64) float64 {\n\tif a > b {\n\t\treturn a\n\t}\n\treturn b\n}\n\n// textBaseline matches CSS line-box placement: half of the extra line-height","sourceCodeStart":1905,"sourceCodeEnd":1941,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/lib/textmeasure/markdown_svg.go#L1905-L1941","documentation":"D2's native (wasm/browser) Markdown-to-SVG renderer walks the parsed HTML tree of Markdown output and only knows how to render a whitelist of block/inline elements. When validateMarkdownSVGNodes encounters any other element name it returns this error. The native renderer is a limited subset of the full JS DOM-based markdown renderer.","triggerScenarios":"Rendering a Markdown diagram to SVG in the WASM/native runtime while the markdown contains HTML elements outside the supported list — e.g. <video>, <audio>, <details>, <summary>, <sup>, <sub>, <iframe>, <button>, custom tags, or raw HTML pasted into the diagram description.","commonSituations":"Users pasting rich HTML into Markdown descriptions; markdown extensions (like footnote or collapsible sections) emitting elements the native renderer doesn't implement; differences between native and hosted rendering behavior.","solutions":["Remove or replace the unsupported HTML element from the Markdown source","Render with the non-native (JS/hosted) markdown renderer which supports full HTML","Escape the HTML so it renders as literal text instead of being parsed as an element","Upgrade d2 to a newer version in case the supported element list has expanded"],"exampleFix":"// before\ndiagram += \"<details><summary>Notes</summary>...</details>\"\n// after\ndiagram += \"**Notes** (details not supported in native SVG)\"","handlingStrategy":"validation","validationCode":"var allowed = map[string]bool{\"html\":true,\"p\":true,\"h1\":true,\"h2\":true,\"h3\":true,\"h4\":true,\"h5\":true,\"h6\":true,\"blockquote\":true,\"ul\":true,\"ol\":true,\"li\":true,\"pre\":true,\"code\":true,\"em\":true,\"b\":true,\"strong\":true,\"del\":true,\"s\":true,\"strike\":true,\"a\":true,\"br\":true,\"hr\":true,\"img\":true,\"table\":true,\"thead\":true,\"tbody\":true,\"tfoot\":true,\"tr\":true,\"td\":true,\"th\":true}\n// pre-scan markdown HTML nodes; reject/sanitize unsupported tags before rendering","typeGuard":"func isSupportedHTMLElement(tag string) bool {\n    return allowed[tag]\n}","tryCatchPattern":"svg, err := RenderMarkdownSVG(md)\nif err != nil {\n    if strings.Contains(err.Error(), \"does not support HTML element\") {\n        return renderFallback(md) // or strip HTML and retry\n    }\n    return err\n}","preventionTips":["Restrict Markdown input to plain Markdown syntax, not raw HTML","Sanitize/strip unsupported HTML tags from user descriptions before rendering","Test rendering in the native (wasm) target, not just the hosted renderer","Pin d2 versions and review the supported element list when upgrading"],"tags":["markdown","svg","wasm","html"],"backgroundTag":"unsupported-html-element","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}