{"record":{"id":"603ed0b8ac3e6c96","repo":"rust-lang/mdBook","slug":"unexpected-event-in-html-block-event","errorCode":null,"errorMessage":"`{}` unexpected event in html block {event:?}","messagePattern":"`(.+?)` unexpected event in html block (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/mdbook-html/src/html/tree.rs","lineNumber":453,"sourceCode":"                                classes.push_str(info);\n                            }\n                            code.insert_attr(\"class\", classes.into());\n                        }\n                    }\n                    CodeBlockKind::Indented => {}\n                }\n                self.push_no_stack(Node::Element(Element::new(\"pre\")));\n                code\n            }\n            Tag::HtmlBlock => {\n                // To process the HTML correctly, this needs to\n                // collect it all into a single string.\n                let mut html = String::new();\n                while let Some(event) = self.events.next() {\n                    match event {\n                        Event::Html(text) | Event::Text(text) => html.push_str(&text),\n                        Event::End(TagEnd::HtmlBlock) => break,\n                        _ => panic!(\n                            \"`{}` unexpected event in html block {event:?}\",\n                            self.options.path.display()\n                        ),\n                    }\n                }\n                self.append_html(&html);\n                // TagEnd::HtmlBlock must not pop.\n                return;\n            }\n            Tag::List(Some(start)) => {\n                let mut ol = Element::new(\"ol\");\n                if start != 1 {\n                    ol.insert_attr(\"start\", format!(\"{start}\").into());\n                }\n                ol\n            }\n            Tag::List(None) => Element::new(\"ul\"),\n            Tag::Item => Element::new(\"li\"),","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/rust-lang/mdBook/blob/dc21064fc21d955a0e1f67e65e336883c3e5260b/crates/mdbook-html/src/html/tree.rs#L435-L471","documentation":"When mdbook-html encounters the start of an HTML block, start_tag drains subsequent pulldown-cmark events until the block ends, accepting only Html, Text, and End(HtmlBlock) events. Any other event inside an html block violates the parser contract and panics with the event shown. This guards against parser-version drift where event grouping changes.","triggerScenarios":"While consuming an html block in start_tag, the pulldown-cmark iterator yields an event other than Html/Text/End(HtmlBlock) — e.g. a Start/End of another tag, Code, or FootnoteReference appearing inside a raw HTML block, usually due to a parser version mismatch or a preprocessor rewriting events inside the block.","commonSituations":"Markdown file whose raw HTML block contains constructs a different parser version splits into extra events; a preprocessor splitting/merging events within html blocks; upgrading pulldown-cmark in a custom build without updating mdbook-html's assumptions.","solutions":["Match the pulldown-cmark version used by your custom mdbook build to the one mdbook-html expects.","Move problematic markdown constructs out of raw HTML blocks in the offending file shown in the panic.","Check preprocessors for event manipulation inside html blocks and fix them to leave blocks intact.","Reproduce with a minimal chapter and file an issue against mdbook if it occurs with stock tooling."],"exampleFix":"// before (src/page.md) — construct inside raw html block\n<div>\n*emph inside raw block*\n</div>\n\n// after — close the block before markdown\n<div>\n</div>\n*emph outside the block*","handlingStrategy":"validation","validationCode":"// reject markdown where raw HTML blocks contain markdown constructs\nfor block in raw_html_blocks(chapter_content)? {\n    if block.contains(\"*\") || block.contains(\"`\") {\n        warn!(\"markdown syntax inside raw HTML block may break rendering: {:?}\", block);\n    }\n}","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(|| render(book))\n    .map_err(|_| anyhow!(\"html block rendering panicked; check markdown inside raw HTML blocks and parser versions\"))?;","preventionTips":["Keep raw HTML blocks free of markdown syntax that the parser may split into other events.","Keep mdbook and pulldown-cmark versions in lockstep.","Rebuild the book after parser upgrades and review any new panics."],"tags":["panic","html-block","markdown-events","parser-version"],"backgroundTag":"unexpected-event-in-html-block","analyzedSha":"dc21064fc21d955a0e1f67e65e336883c3e5260b","analyzedAt":"2026-09-01T10:15:12.134Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}