parserOptions.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.parserOptions = void 0;
  4. const shared_1 = require("@vue/shared");
  5. const decodeHtml_1 = require("./decodeHtml");
  6. const isRawTextContainer = /*#__PURE__*/ (0, shared_1.makeMap)('style,iframe,script,noscript', true);
  7. exports.parserOptions = {
  8. isVoidTag: shared_1.isVoidTag,
  9. isNativeTag: (tag) => (0, shared_1.isHTMLTag)(tag) || (0, shared_1.isSVGTag)(tag),
  10. isPreTag: (tag) => tag === 'pre',
  11. decodeEntities: decodeHtml_1.decodeHtml,
  12. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  13. getNamespace(tag, parent) {
  14. let ns = parent ? parent.ns : 0 /* DOMNamespaces.HTML */;
  15. if (parent && ns === 2 /* DOMNamespaces.MATH_ML */) {
  16. if (parent.tag === 'annotation-xml') {
  17. if (tag === 'svg') {
  18. return 1 /* DOMNamespaces.SVG */;
  19. }
  20. if (parent.props.some((a) => a.type === 6 /* NodeTypes.ATTRIBUTE */ &&
  21. a.name === 'encoding' &&
  22. a.value != null &&
  23. (a.value.content === 'text/html' ||
  24. a.value.content === 'application/xhtml+xml'))) {
  25. ns = 0 /* DOMNamespaces.HTML */;
  26. }
  27. }
  28. else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
  29. tag !== 'mglyph' &&
  30. tag !== 'malignmark') {
  31. ns = 0 /* DOMNamespaces.HTML */;
  32. }
  33. }
  34. else if (parent && ns === 1 /* DOMNamespaces.SVG */) {
  35. if (parent.tag === 'foreignObject' ||
  36. parent.tag === 'desc' ||
  37. parent.tag === 'title') {
  38. ns = 0 /* DOMNamespaces.HTML */;
  39. }
  40. }
  41. if (ns === 0 /* DOMNamespaces.HTML */) {
  42. if (tag === 'svg') {
  43. return 1 /* DOMNamespaces.SVG */;
  44. }
  45. if (tag === 'math') {
  46. return 2 /* DOMNamespaces.MATH_ML */;
  47. }
  48. }
  49. return ns;
  50. },
  51. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  52. getTextMode({ tag, ns }) {
  53. if (ns === 0 /* DOMNamespaces.HTML */) {
  54. if (tag === 'textarea' || tag === 'title') {
  55. return 1 /* TextModes.RCDATA */;
  56. }
  57. if (isRawTextContainer(tag)) {
  58. return 2 /* TextModes.RAWTEXT */;
  59. }
  60. }
  61. return 0 /* TextModes.DATA */;
  62. },
  63. };