##// END OF EJS Templates
extract svg tag from svg files...
MinRK -
Show More
@@ -17,6 +17,8 b' Authors:'
17 # Imports
17 # Imports
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19
19
20 from xml.dom import minidom
21
20 from .displaypub import (
22 from .displaypub import (
21 publish_pretty, publish_html,
23 publish_pretty, publish_html,
22 publish_latex, publish_svg,
24 publish_latex, publish_svg,
@@ -300,7 +302,32 b' class Math(DisplayObject):'
300
302
301
303
302 class SVG(DisplayObject):
304 class SVG(DisplayObject):
303
305
306 # wrap data in a property, which extracts the <svg> tag, discarding
307 # document headers
308 _data = None
309
310 @property
311 def data(self):
312 return self._data
313
314 @data.setter
315 def data(self, svg):
316 if svg is None:
317 self._data = None
318 return
319 # parse into dom object
320 x = minidom.parseString(svg)
321 # get svg tag (should be 1)
322 found_svg = x.getElementsByTagName('svg')
323 if found_svg:
324 svg = found_svg[0].toxml()
325 else:
326 # fallback on the input, trust the user
327 # but this is probably an error.
328 pass
329 self._data = svg
330
304 def _repr_svg_(self):
331 def _repr_svg_(self):
305 return self.data
332 return self.data
306
333
General Comments 0
You need to be logged in to leave comments. Login now