@@ -193,15 +193,11 @@ class PaperCanvas extends React.Component {
193
193
}
194
194
importSvg ( svg , rotationCenterX , rotationCenterY ) {
195
195
const paperCanvas = this ;
196
- // Pre-process SVG to prevent parsing errors (discussion from #213)
197
- // 1. Remove svg: namespace on elements.
198
- svg = svg . split ( / < \s * s v g : / ) . join ( '<' ) ;
199
- svg = svg . split ( / < \/ \s * s v g : / ) . join ( '</' ) ;
200
- // 2. Add root svg namespace if it does not exist.
201
- const svgAttrs = svg . match ( / < s v g [ ^ > ] * > / ) ;
202
- if ( svgAttrs && svgAttrs [ 0 ] . indexOf ( 'xmlns=' ) === - 1 ) {
203
- svg = svg . replace (
204
- '<svg ' , '<svg xmlns="http://www.w3.org/2000/svg" ' ) ;
196
+ if ( this . props . fixupSvgStringFn ) {
197
+ // Pre-process SVG to prevent parsing errors (discussion from #213)
198
+ svg = this . props . fixupSvgStringFn ( svg ) ;
199
+ } else {
200
+ log . error ( 'Some SVGs may crash the paint editor if fixupSvgStringFn prop is not set on PaintEditor.' ) ;
205
201
}
206
202
207
203
// Get the origin which the viewBox is defined relative to. During import, Paper will translate
@@ -351,6 +347,7 @@ PaperCanvas.propTypes = {
351
347
clearSelectedItems : PropTypes . func . isRequired ,
352
348
clearUndo : PropTypes . func . isRequired ,
353
349
cursor : PropTypes . string ,
350
+ fixupSvgStringFn : PropTypes . func ,
354
351
format : PropTypes . oneOf ( Object . keys ( Formats ) ) ,
355
352
image : PropTypes . oneOfType ( [
356
353
PropTypes . string ,
0 commit comments