fix: svg foreignobject in code blocks (#10339)

* fix: svg foreignobject in code blocks

* fix: set white-space explicitly
This commit is contained in:
one 2025-09-25 18:02:06 +08:00 committed by GitHub
parent 067ecb5e8e
commit caad0bc005
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,7 +18,8 @@ export function renderSvgInShadowHost(svgContent: string, hostElement: HTMLEleme
// Sanitize the SVG content
const sanitizedContent = DOMPurify.sanitize(svgContent, {
ADD_TAGS: ['animate', 'foreignObject', 'use'],
ADD_ATTR: ['from', 'to']
ADD_ATTR: ['from', 'to'],
HTML_INTEGRATION_POINTS: { foreignobject: true }
})
const shadowRoot = hostElement.shadowRoot || hostElement.attachShadow({ mode: 'open' })
@ -36,6 +37,7 @@ export function renderSvgInShadowHost(svgContent: string, hostElement: HTMLEleme
border-radius: var(--shadow-host-border-radius);
padding: 1em;
overflow: hidden; /* Prevent scrollbars, as scaling is now handled */
white-space: normal;
display: block;
position: relative;
width: 100%;