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 74
74
75
75
let mounted = false ;
76
76
77
- $: svgCode = svg (code);
77
+ $: svgCode = prettySVG ( svg (code) );
78
78
79
79
$: full = / preserveAspectRatio/ i .test (code);
80
80
85
85
}
86
86
}
87
87
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
+
88
114
function isNull (value ) {
89
115
return value === null || value === undefined ;
90
116
}
319
345
320
346
.svg {
321
347
display : block ;
348
+ place-items : normal ;
322
349
padding : 1.6em ;
323
350
}
324
351
You can’t perform that action at this time.
0 commit comments