File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change 7474
7575 let mounted = false ;
7676
77- $: svgCode = svg (code);
77+ $: svgCode = prettySVG ( svg (code) );
7878
7979 $: full = / preserveAspectRatio/ i .test (code);
8080
8585 }
8686 }
8787
88+ function prettySVG (input ) {
89+ try {
90+ let xmlDoc = new DOMParser ().parseFromString (input, ' application/xml' );
91+ let xsltDoc = new DOMParser ().parseFromString (`
92+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
93+ <xsl:strip-space elements="*"/>
94+ <xsl:template match="para[content-style][not(text())]">
95+ <xsl:value-of select="normalize-space(.)"/>
96+ </xsl:template>
97+ <xsl:template match="node()|@*">
98+ <xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>
99+ </xsl:template>
100+ <xsl:output indent="yes"/>
101+ </xsl:stylesheet>
102+ ` ,' application/xml' );
103+
104+ let xsltProcessor = new XSLTProcessor ();
105+ xsltProcessor .importStylesheet (xsltDoc);
106+ let resultDoc = xsltProcessor .transformToDocument (xmlDoc);
107+ let resultXml = new XMLSerializer ().serializeToString (resultDoc);
108+ return resultXml;
109+ } catch (e) {
110+ return input;
111+ }
112+ }
113+
88114 function isNull (value ) {
89115 return value === null || value === undefined ;
90116 }
319345
320346 .svg {
321347 display : block ;
348+ place-items : normal ;
322349 padding : 1.6em ;
323350 }
324351
You can’t perform that action at this time.
0 commit comments