2023-11-19 11:20:05 +08:00
|
|
|
import { Namespaces, NodeTypes, type ParserOptions } from '@vue/compiler-core'
|
2023-12-08 18:25:01 +08:00
|
|
|
import { isHTMLTag, isMathMLTag, isSVGTag, isVoidTag } from '@vue/shared'
|
2020-02-08 02:56:18 +08:00
|
|
|
import { TRANSITION, TRANSITION_GROUP } from './runtimeHelpers'
|
2020-04-09 06:51:25 +08:00
|
|
|
import { decodeHtmlBrowser } from './decodeHtmlBrowser'
|
2019-10-25 22:35:44 +08:00
|
|
|
|
2020-04-09 06:51:25 +08:00
|
|
|
export const parserOptions: ParserOptions = {
|
2023-11-17 14:17:30 +08:00
|
|
|
parseMode: 'html',
|
2019-10-11 02:54:06 +08:00
|
|
|
isVoidTag,
|
2023-12-08 18:25:01 +08:00
|
|
|
isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
|
2019-10-25 04:42:09 +08:00
|
|
|
isPreTag: tag => tag === 'pre',
|
2023-11-18 21:39:31 +08:00
|
|
|
decodeEntities: __BROWSER__ ? decodeHtmlBrowser : undefined,
|
2019-10-11 02:54:06 +08:00
|
|
|
|
2023-11-19 11:20:05 +08:00
|
|
|
isBuiltInComponent: tag => {
|
2023-11-16 17:30:00 +08:00
|
|
|
if (tag === 'Transition' || tag === 'transition') {
|
2020-02-08 02:56:18 +08:00
|
|
|
return TRANSITION
|
2023-11-16 17:30:00 +08:00
|
|
|
} else if (tag === 'TransitionGroup' || tag === 'transition-group') {
|
2020-02-08 02:56:18 +08:00
|
|
|
return TRANSITION_GROUP
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-09-17 23:07:46 +08:00
|
|
|
// https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
|
2023-11-19 11:20:05 +08:00
|
|
|
getNamespace(tag, parent, rootNamespace) {
|
|
|
|
let ns = parent ? parent.ns : rootNamespace
|
|
|
|
if (parent && ns === Namespaces.MATH_ML) {
|
2019-09-17 23:07:46 +08:00
|
|
|
if (parent.tag === 'annotation-xml') {
|
|
|
|
if (tag === 'svg') {
|
2023-11-19 11:20:05 +08:00
|
|
|
return Namespaces.SVG
|
2019-09-17 23:07:46 +08:00
|
|
|
}
|
|
|
|
if (
|
2019-09-23 01:05:19 +08:00
|
|
|
parent.props.some(
|
2019-09-17 23:07:46 +08:00
|
|
|
a =>
|
2019-09-23 01:05:19 +08:00
|
|
|
a.type === NodeTypes.ATTRIBUTE &&
|
2019-09-17 23:07:46 +08:00
|
|
|
a.name === 'encoding' &&
|
|
|
|
a.value != null &&
|
|
|
|
(a.value.content === 'text/html' ||
|
|
|
|
a.value.content === 'application/xhtml+xml'),
|
|
|
|
)
|
|
|
|
) {
|
2023-11-19 11:20:05 +08:00
|
|
|
ns = Namespaces.HTML
|
2019-09-17 23:07:46 +08:00
|
|
|
}
|
|
|
|
} else if (
|
2019-09-18 00:26:09 +08:00
|
|
|
/^m(?:[ions]|text)$/.test(parent.tag) &&
|
2019-09-17 23:07:46 +08:00
|
|
|
tag !== 'mglyph' &&
|
|
|
|
tag !== 'malignmark'
|
|
|
|
) {
|
2023-11-19 11:20:05 +08:00
|
|
|
ns = Namespaces.HTML
|
2019-09-17 23:07:46 +08:00
|
|
|
}
|
2023-11-19 11:20:05 +08:00
|
|
|
} else if (parent && ns === Namespaces.SVG) {
|
2019-09-17 23:07:46 +08:00
|
|
|
if (
|
|
|
|
parent.tag === 'foreignObject' ||
|
|
|
|
parent.tag === 'desc' ||
|
|
|
|
parent.tag === 'title'
|
|
|
|
) {
|
2023-11-19 11:20:05 +08:00
|
|
|
ns = Namespaces.HTML
|
2019-09-17 23:07:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-19 11:20:05 +08:00
|
|
|
if (ns === Namespaces.HTML) {
|
2019-09-17 23:07:46 +08:00
|
|
|
if (tag === 'svg') {
|
2023-11-19 11:20:05 +08:00
|
|
|
return Namespaces.SVG
|
2019-09-17 23:07:46 +08:00
|
|
|
}
|
|
|
|
if (tag === 'math') {
|
2023-11-19 11:20:05 +08:00
|
|
|
return Namespaces.MATH_ML
|
2019-09-17 23:07:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ns
|
|
|
|
},
|
|
|
|
}
|