]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compile-dom): should be able to stringify mathML (#11891)
authoredison <daiwei521@126.com>
Mon, 16 Sep 2024 02:58:23 +0000 (10:58 +0800)
committerGitHub <noreply@github.com>
Mon, 16 Sep 2024 02:58:23 +0000 (10:58 +0800)
packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
packages/compiler-dom/src/transforms/stringifyStatic.ts
packages/shared/src/domAttrConfig.ts

index 7530a59fa4f398b972274a2708c3015b7e652034..a35b5223198b1cfcaaca9c2ab783ded320fd8a1a 100644 (file)
@@ -389,6 +389,24 @@ describe('stringify static html', () => {
     ])
   })
 
+  test('should stringify mathML', () => {
+    const math = `<math xmlns="http://www.w3.org/1998/Math/MathML">`
+    const repeated = `<ms>1</ms>`
+    const { ast } = compileWithStringify(
+      `<div>${math}${repeat(
+        repeated,
+        StringifyThresholds.NODE_COUNT,
+      )}</math></div>`,
+    )
+
+    expect(ast.cached).toMatchObject([
+      cachedArrayStaticNodeMatcher(
+        `${math}${repeat(repeated, StringifyThresholds.NODE_COUNT)}</math>`,
+        1,
+      ),
+    ])
+  })
+
   // #5439
   test('stringify v-html', () => {
     const { code } = compileWithStringify(`
index bb3d26e817b72740d7864100e69e968fb27258ee..a608ea3c4b34e2c783834a583076cb6f1f1b73de 100644 (file)
@@ -24,6 +24,7 @@ import {
   isArray,
   isBooleanAttr,
   isKnownHtmlAttr,
+  isKnownMathMLAttr,
   isKnownSvgAttr,
   isString,
   isSymbol,
@@ -190,7 +191,9 @@ const isStringifiableAttr = (name: string, ns: Namespaces) => {
       ? isKnownHtmlAttr(name)
       : ns === Namespaces.SVG
         ? isKnownSvgAttr(name)
-        : false) || dataAriaRE.test(name)
+        : ns === Namespaces.MATH_ML
+          ? isKnownMathMLAttr(name)
+          : false) || dataAriaRE.test(name)
   )
 }
 
index e62a3c2ef4912ff8b89306f1b0031409e1708ae8..b5f0166327fb3133e765fd47ff40a475ab3824de 100644 (file)
@@ -123,6 +123,25 @@ export const isKnownSvgAttr: (key: string) => boolean = /*@__PURE__*/ makeMap(
     `xml:space,y,y1,y2,yChannelSelector,z,zoomAndPan`,
 )
 
+/**
+ * Generated from https://developer.mozilla.org/en-US/docs/Web/MathML/Attribute
+ */
+export const isKnownMathMLAttr: (key: string) => boolean =
+  /*@__PURE__*/ makeMap(
+    `accent,accentunder,actiontype,align,alignmentscope,altimg,altimg-height,` +
+      `altimg-valign,altimg-width,alttext,bevelled,close,columnsalign,columnlines,` +
+      `columnspan,denomalign,depth,dir,display,displaystyle,encoding,` +
+      `equalcolumns,equalrows,fence,fontstyle,fontweight,form,frame,framespacing,` +
+      `groupalign,height,href,id,indentalign,indentalignfirst,indentalignlast,` +
+      `indentshift,indentshiftfirst,indentshiftlast,indextype,justify,` +
+      `largetop,largeop,lquote,lspace,mathbackground,mathcolor,mathsize,` +
+      `mathvariant,maxsize,minlabelspacing,mode,other,overflow,position,` +
+      `rowalign,rowlines,rowspan,rquote,rspace,scriptlevel,scriptminsize,` +
+      `scriptsizemultiplier,selection,separator,separators,shift,side,` +
+      `src,stackalign,stretchy,subscriptshift,superscriptshift,symmetric,` +
+      `voffset,width,widths,xlink:href,xlink:show,xlink:type,xmlns`,
+  )
+
 /**
  * Shared between server-renderer and runtime-core hydration logic
  */