{"record":{"id":"215e282a6e17946d","repo":"swc-project/swc","slug":"starttagintable","errorCode":"StartTagInTable","errorMessage":"Start tag \"{tag_name}\" seen in \"table\"","messagePattern":"Start tag \"(.+?)\" seen in \"table\"","errorType":"validation","errorClass":"swc_html_parser::error::Error","httpStatus":null,"severity":"warning","filePath":"crates/swc_html_parser/src/parser/mod.rs","lineNumber":6711,"sourceCode":"                        }\n                        _ => {\n                            unreachable!();\n                        }\n                    },\n                }\n            }\n        }\n\n        Ok(())\n    }\n\n    fn process_token_in_table_insertion_mode_anything_else(\n        &mut self,\n        token_and_info: &mut TokenAndInfo,\n    ) -> PResult<()> {\n        match &token_and_info.token {\n            Token::StartTag { tag_name, .. } => {\n                self.errors.push(Error::new(\n                    token_and_info.span,\n                    ErrorKind::StartTagInTable(tag_name.clone()),\n                ));\n            }\n            Token::EndTag { tag_name, .. } => {\n                self.errors.push(Error::new(\n                    token_and_info.span,\n                    ErrorKind::StrayEndTag(tag_name.clone()),\n                ));\n            }\n            Token::Character { .. } => {\n                self.errors.push(Error::new(\n                    token_and_info.span,\n                    ErrorKind::NonSpaceCharacterInTable,\n                ));\n            }\n            _ => {\n                unreachable!();","sourceCodeStart":6693,"sourceCodeEnd":6729,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_html_parser/src/parser/mod.rs#L6693-L6729","documentation":"Inside a table (the 'in table' insertion mode) only a narrow set of table-related tags is allowed; anything else triggers the foster-parenting path. This error is reported when the unexpected token is a start tag: `process_token_in_table_insertion_mode_anything_else` (crates/swc_html_parser/src/parser/mod.rs:6711) records the tag name, then the parser enables foster parenting and reprocesses the token so the element is inserted before/around the table, per the HTML standard.","triggerScenarios":"Parsing markup such as `<table><div>x</div></table>` or `<table><span>hi</span></table>` — any start tag that is not legal in the table insertion mode (not caption/colgroup/tbody/tfoot/thead/tr/td/th/style/script/template/form/input[type=hidden]). The div/span start tag produces `StartTagInTable(\"div\")` and the node is foster-parented outside the table.","commonSituations":"Wrapping layout divs inside table-based email templates; legacy table layouts with `<font>`/`<span>` between rows; CMS output injecting wrapper tags into tables; copy-pasting div-based content into table cells at the wrong nesting level.","solutions":["Move the non-table element out of <table>, into a <td>/<th> cell or before/after the table","If it is styling/scripting, use the allowed <style>/<script> or <template> exceptions","Restructure legacy table layouts so only legal table children appear directly under table","Accept the recovered (foster-parented) output but keep the diagnostic in your HTML lint report"],"exampleFix":"<!-- before -->\n<table><div>x</div><tr><td>cell</td></tr></table>\n<!-- after -->\n<div>x</div><table><tr><td>cell</td></tr></table>","handlingStrategy":"validation","validationCode":"// Flag non-table elements directly under <table> (foster-parenting cases)\nfunction assertTableChildren(tableHtml: string): void {\n  const inner = tableHtml.replace(/<table[^>]*>|<\\/?(table|tbody|thead|tfoot|tr|td|th|caption|colgroup|col|style|script|template|form)\\b[^>]*>/gi, '');\n  if (/<[a-zA-Z]/.test(inner)) throw new Error('non-table element inside <table>');\n}","typeGuard":null,"tryCatchPattern":"for err in parser.take_errors() {\n    if matches!(err.kind, ErrorKind::StartTagInTable(_)) {\n        // parser recovers via foster parenting; verify placement in output\n    }\n}","preventionTips":["Place layout divs and spans outside the table or inside td/th cells","Only style/script/template/form/input[type=hidden] may sit directly in table","Snapshot-test the normalized tree for table-heavy templates (email HTML)"],"tags":["html","table","foster-parenting","parse-error","nesting"],"backgroundTag":"html5-parse-error","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}