Skip to content

Commit 85c138c

Browse files
authoredSep 16, 2024··
fix(compile-dom): should be able to stringify mathML (#11891)
1 parent 49fa673 commit 85c138c

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed
 

‎packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,24 @@ describe('stringify static html', () => {
389389
])
390390
})
391391

392+
test('should stringify mathML', () => {
393+
const math = `<math xmlns="http://www.w3.org/1998/Math/MathML">`
394+
const repeated = `<ms>1</ms>`
395+
const { ast } = compileWithStringify(
396+
`<div>${math}${repeat(
397+
repeated,
398+
StringifyThresholds.NODE_COUNT,
399+
)}</math></div>`,
400+
)
401+
402+
expect(ast.cached).toMatchObject([
403+
cachedArrayStaticNodeMatcher(
404+
`${math}${repeat(repeated, StringifyThresholds.NODE_COUNT)}</math>`,
405+
1,
406+
),
407+
])
408+
})
409+
392410
// #5439
393411
test('stringify v-html', () => {
394412
const { code } = compileWithStringify(`

‎packages/compiler-dom/src/transforms/stringifyStatic.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
isArray,
2525
isBooleanAttr,
2626
isKnownHtmlAttr,
27+
isKnownMathMLAttr,
2728
isKnownSvgAttr,
2829
isString,
2930
isSymbol,
@@ -190,7 +191,9 @@ const isStringifiableAttr = (name: string, ns: Namespaces) => {
190191
? isKnownHtmlAttr(name)
191192
: ns === Namespaces.SVG
192193
? isKnownSvgAttr(name)
193-
: false) || dataAriaRE.test(name)
194+
: ns === Namespaces.MATH_ML
195+
? isKnownMathMLAttr(name)
196+
: false) || dataAriaRE.test(name)
194197
)
195198
}
196199

‎packages/shared/src/domAttrConfig.ts

+19
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ export const isKnownSvgAttr: (key: string) => boolean = /*@__PURE__*/ makeMap(
123123
`xml:space,y,y1,y2,yChannelSelector,z,zoomAndPan`,
124124
)
125125

126+
/**
127+
* Generated from https://developer.mozilla.org/en-US/docs/Web/MathML/Attribute
128+
*/
129+
export const isKnownMathMLAttr: (key: string) => boolean =
130+
/*@__PURE__*/ makeMap(
131+
`accent,accentunder,actiontype,align,alignmentscope,altimg,altimg-height,` +
132+
`altimg-valign,altimg-width,alttext,bevelled,close,columnsalign,columnlines,` +
133+
`columnspan,denomalign,depth,dir,display,displaystyle,encoding,` +
134+
`equalcolumns,equalrows,fence,fontstyle,fontweight,form,frame,framespacing,` +
135+
`groupalign,height,href,id,indentalign,indentalignfirst,indentalignlast,` +
136+
`indentshift,indentshiftfirst,indentshiftlast,indextype,justify,` +
137+
`largetop,largeop,lquote,lspace,mathbackground,mathcolor,mathsize,` +
138+
`mathvariant,maxsize,minlabelspacing,mode,other,overflow,position,` +
139+
`rowalign,rowlines,rowspan,rquote,rspace,scriptlevel,scriptminsize,` +
140+
`scriptsizemultiplier,selection,separator,separators,shift,side,` +
141+
`src,stackalign,stretchy,subscriptshift,superscriptshift,symmetric,` +
142+
`voffset,width,widths,xlink:href,xlink:show,xlink:type,xmlns`,
143+
)
144+
126145
/**
127146
* Shared between server-renderer and runtime-core hydration logic
128147
*/

0 commit comments

Comments
 (0)
Please sign in to comment.