Skip to content

feat(compile-dom): stringify mathML #11891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down
5 changes: 4 additions & 1 deletion packages/compiler-dom/src/transforms/stringifyStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
isArray,
isBooleanAttr,
isKnownHtmlAttr,
isKnownMathMLAttr,
isKnownSvgAttr,
isString,
isSymbol,
Expand Down Expand Up @@ -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)
)
}

Expand Down
19 changes: 19 additions & 0 deletions packages/shared/src/domAttrConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down