| 21 | |
| 22 | // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher |
| 23 | getNamespace(tag, parent, rootNamespace) { |
| 24 | let ns = parent ? parent.ns : rootNamespace |
| 25 | if (parent && ns === Namespaces.MATH_ML) { |
| 26 | if (parent.tag === 'annotation-xml') { |
| 27 | if (tag === 'svg') { |
| 28 | return Namespaces.SVG |
| 29 | } |
| 30 | if ( |
| 31 | parent.props.some( |
| 32 | a => |
| 33 | a.type === NodeTypes.ATTRIBUTE && |
| 34 | a.name === 'encoding' && |
| 35 | a.value != null && |
| 36 | (a.value.content === 'text/html' || |
| 37 | a.value.content === 'application/xhtml+xml'), |
| 38 | ) |
| 39 | ) { |
| 40 | ns = Namespaces.HTML |
| 41 | } |
| 42 | } else if ( |
| 43 | /^m(?:[ions]|text)$/.test(parent.tag) && |
| 44 | tag !== 'mglyph' && |
| 45 | tag !== 'malignmark' |
| 46 | ) { |
| 47 | ns = Namespaces.HTML |
| 48 | } |
| 49 | } else if (parent && ns === Namespaces.SVG) { |
| 50 | if ( |
| 51 | parent.tag === 'foreignObject' || |
| 52 | parent.tag === 'desc' || |
| 53 | parent.tag === 'title' |
| 54 | ) { |
| 55 | ns = Namespaces.HTML |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if (ns === Namespaces.HTML) { |
| 60 | if (tag === 'svg') { |
| 61 | return Namespaces.SVG |
| 62 | } |
| 63 | if (tag === 'math') { |
| 64 | return Namespaces.MATH_ML |
| 65 | } |
| 66 | } |
| 67 | return ns |
| 68 | }, |
| 69 | } |