| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import {
- TextModes,
- ParserOptions,
- ElementNode,
- Namespaces,
- NodeTypes
- } from '@vue/compiler-core'
- import { isVoidTag, isHTMLTag, isSVGTag } from './tagConfig'
- export const enum DOMNamespaces {
- HTML = Namespaces.HTML,
- SVG,
- MATH_ML
- }
- export const parserOptionsMinimal: ParserOptions = {
- isVoidTag,
- isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
- isPreTag: tag => tag === 'pre',
- // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
- getNamespace(tag: string, parent: ElementNode | undefined): DOMNamespaces {
- let ns = parent ? parent.ns : DOMNamespaces.HTML
- if (parent && ns === DOMNamespaces.MATH_ML) {
- if (parent.tag === 'annotation-xml') {
- if (tag === 'svg') {
- return DOMNamespaces.SVG
- }
- if (
- parent.props.some(
- a =>
- a.type === NodeTypes.ATTRIBUTE &&
- a.name === 'encoding' &&
- a.value != null &&
- (a.value.content === 'text/html' ||
- a.value.content === 'application/xhtml+xml')
- )
- ) {
- ns = DOMNamespaces.HTML
- }
- } else if (
- /^m(?:[ions]|text)$/.test(parent.tag) &&
- tag !== 'mglyph' &&
- tag !== 'malignmark'
- ) {
- ns = DOMNamespaces.HTML
- }
- } else if (parent && ns === DOMNamespaces.SVG) {
- if (
- parent.tag === 'foreignObject' ||
- parent.tag === 'desc' ||
- parent.tag === 'title'
- ) {
- ns = DOMNamespaces.HTML
- }
- }
- if (ns === DOMNamespaces.HTML) {
- if (tag === 'svg') {
- return DOMNamespaces.SVG
- }
- if (tag === 'math') {
- return DOMNamespaces.MATH_ML
- }
- }
- return ns
- },
- // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
- getTextMode(tag: string, ns: DOMNamespaces): TextModes {
- if (ns === DOMNamespaces.HTML) {
- if (tag === 'textarea' || tag === 'title') {
- return TextModes.RCDATA
- }
- if (
- /^(?:style|xmp|iframe|noembed|noframes|script|noscript)$/i.test(tag)
- ) {
- return TextModes.RAWTEXT
- }
- }
- return TextModes.DATA
- }
- }
|