{"record":{"id":"48b45859c99f564e","repo":"squidfunk/mkdocs-material","slug":"couldn-t-parse-due-to-possible-syntax-error-in-htm","errorCode":null,"errorMessage":"Couldn't parse due to possible syntax error in HTML: \n\n{fragment}","messagePattern":"Couldn't parse due to possible syntax error in HTML: \n\n(.+?)","errorType":"exception","errorClass":"PluginError","httpStatus":null,"severity":"error","filePath":"src/plugins/privacy/plugin.py","lineNumber":317,"sourceCode":"        return False\n\n    # -------------------------------------------------------------------------\n\n    # Parse a fragment\n    def _parse_fragment(self, fragment: str):\n        parser = FragmentParser()\n        parser.feed(fragment)\n        parser.close()\n\n        # Check parse result and return element\n        if isinstance(parser.result, Element):\n            return parser.result\n\n        # Otherwise, raise a plugin error - if the author accidentally used\n        # invalid HTML inside of the tag, e.g., forget a opening or closing\n        # quote, we need to catch this here, as we're using pretty basic\n        # regular expression based extraction\n        raise PluginError(\n            \"Couldn't parse due to possible syntax error in HTML: \\n\\n\"\n            + fragment\n        )\n\n    # Parse and extract all external assets from a media file using a preset\n    # regular expression, and return all URLs found.\n    def _parse_media(self, initiator: File) -> list[URL]:\n        _, extension = posixpath.splitext(initiator.dest_uri)\n        if extension not in self.assets_expr_map:\n            return []\n\n        # Skip if source path is not set, which might be true for generated\n        # files or for files that were added programatically in plugins\n        if not initiator.abs_src_path:\n            return []\n\n        # Find and extract all external asset URLs\n        expr = re.compile(self.assets_expr_map[extension], flags = re.I | re.M)","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/squidfunk/mkdocs-material/blob/e2136532f40aed98af1f6497c0cc6a3cff9f759b/src/plugins/privacy/plugin.py#L299-L335","documentation":"The privacy plugin extracts external asset URLs from page HTML using regex-based parsing. When the tag fragment it extracted cannot be parsed — typically because the author wrote invalid HTML such as an unclosed or unquoted attribute — the plugin aborts with PluginError showing the offending fragment, since regex extraction cannot reliably proceed on malformed markup.","triggerScenarios":"on_page_content (or replace) encounters an external-asset tag in the page whose extracted HTML fragment fails the plugin's parser, e.g. <img src=\"https://... > with a missing closing quote, or a missing closing tag, so the regex extraction yields an unparseable fragment.","commonSituations":"Hand-edited HTML with a forgotten closing quote or tag; templating/macros generating attributes with unescaped quotes; minifiers or shortcodes emitting non-well-formed tags that confuse the regex-based extractor.","solutions":["Inspect the printed fragment and fix the HTML syntax error (missing quote, missing '>' or closing tag) in the source Markdown/HTML","Validate the page HTML (e.g. run a linter or paste into an HTML validator) to find the malformed tag","If generated by a macro/template, fix the generator to emit well-formed attributes"],"exampleFix":"<!-- before -->\n<img src=\"https://example.com/logo.png alt=\"logo\">\n<!-- after -->\n<img src=\"https://example.com/logo.png\" alt=\"logo\">","handlingStrategy":"validation","validationCode":"from html.parser import HTMLParser\nclass _V(HTMLParser):\n    def error(self, m): raise ValueError(m)\n_V().feed(fragment)  # raises on obviously malformed markup before build","typeGuard":null,"tryCatchPattern":"try:\n    mkdocs build\nexcept SystemExit:\n    # message prints the failing fragment; fix the quoted HTML\n    pass","preventionTips":["Always quote HTML attribute values in Markdown/HTML blocks","Run an HTML linter (htmlhint/tidy) over custom HTML in docs","If generating HTML via macros, escape attribute values and test output"],"tags":["html","parsing","mkdocs","privacy-plugin","syntax-error"],"backgroundTag":"invalid-html-fragment","analyzedSha":"e2136532f40aed98af1f6497c0cc6a3cff9f759b","analyzedAt":"2026-08-29T11:20:04.299Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}