From 86c18e25d621f2bb851a5bce471d86f7fb09b5f7 Mon Sep 17 00:00:00 2001 From: daiwei Date: Wed, 11 Sep 2024 11:01:03 +0800 Subject: [PATCH 1/2] feat(compile-dom): stringify mathML --- .../transforms/stringifyStatic.spec.ts | 18 ++++++++++++++++++ .../src/transforms/stringifyStatic.ts | 5 ++++- packages/shared/src/domAttrConfig.ts | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts index fbf5718e65e..13064ea9ae5 100644 --- a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts +++ b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts @@ -389,6 +389,24 @@ describe('stringify static html', () => { ]) }) + test('should stringify mathML', () => { + const math = `` + const repeated = `1` + const { ast } = compileWithStringify( + `
${math}${repeat( + repeated, + StringifyThresholds.NODE_COUNT, + )}
`, + ) + + expect(ast.cached).toMatchObject([ + cachedArrayStaticNodeMatcher( + `${math}${repeat(repeated, StringifyThresholds.NODE_COUNT)}`, + 1, + ), + ]) + }) + // #5439 test('stringify v-html', () => { const { code } = compileWithStringify(` diff --git a/packages/compiler-dom/src/transforms/stringifyStatic.ts b/packages/compiler-dom/src/transforms/stringifyStatic.ts index 05535a2c312..5a1301789c3 100644 --- a/packages/compiler-dom/src/transforms/stringifyStatic.ts +++ b/packages/compiler-dom/src/transforms/stringifyStatic.ts @@ -26,6 +26,7 @@ import { isArray, isBooleanAttr, isKnownHtmlAttr, + isKnownMathMLAttr, isKnownSvgAttr, isString, isSymbol, @@ -184,7 +185,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) ) } diff --git a/packages/shared/src/domAttrConfig.ts b/packages/shared/src/domAttrConfig.ts index e62a3c2ef49..71ad80ac38b 100644 --- a/packages/shared/src/domAttrConfig.ts +++ b/packages/shared/src/domAttrConfig.ts @@ -123,6 +123,22 @@ export const isKnownSvgAttr: (key: string) => boolean = /*@__PURE__*/ makeMap( `xml:space,y,y1,y2,yChannelSelector,z,zoomAndPan`, ) +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 */ From e92e5585226e137bde18268fe65676c7a8ece180 Mon Sep 17 00:00:00 2001 From: daiwei Date: Wed, 11 Sep 2024 11:14:09 +0800 Subject: [PATCH 2/2] chore: add comments --- packages/shared/src/domAttrConfig.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/shared/src/domAttrConfig.ts b/packages/shared/src/domAttrConfig.ts index 71ad80ac38b..b5f0166327f 100644 --- a/packages/shared/src/domAttrConfig.ts +++ b/packages/shared/src/domAttrConfig.ts @@ -123,6 +123,9 @@ 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,` +