/// Table-context and foreign-content (SVG/MathML) helpers, split out so /// HTMLDocument's own body stays within the type-body length budget. extension HTMLDocument { /// Tags that close an open `` that an opening table tag should close /// (a select inside a table), or nil when there is none. func selectInTableToClose(for name: String) -> Int? { guard Self.closesSelectInTable.contains(name), let selectIndex = openBody.lastIndex(where: { tagName($0) == "select" }), selectIndex >= 1, openBody[.. [Attribute] { guard namespace == ForeignNamespace.svg else { return attributes } return attributes.map { attribute in guard let adjusted = PureXML.HTML.ForeignNames.svgAttributes[attribute.name.localName.lowercased()] else { return attribute } return Attribute(adjusted, attribute.value) } } /// The foreign-content namespace for a body element: SVG/MathML on entry, the /// nearest open foreign ancestor's, or HTML (nil) inside an integration point. func bodyForeignNamespace(for name: String) -> String? { if name == "svg" { return ForeignNamespace.svg } if name == "math" { return ForeignNamespace.mathml } for node in openBody.reversed() { guard let namespace = node.name?.namespaceURI else { continue } if Self.svgIntegrationPoints.contains(tagName(node)) { return nil } return namespace } return nil } }