Some SVG images render incorrectly in htmlnotebook #700

Closed
stefanv opened this Issue Aug 15, 2011 · 3 comments

Projects

None yet

3 participants

@stefanv
stefanv commented Aug 15, 2011

When displaying this SVG file in the htmlnotebook:

import IPython.core.display as d
d.SVG(filename='caution.svg')

The output is "]>" + image.

@minrk
Member
minrk commented Aug 15, 2011

The issue probably comes from the fact that the DOCTYPE header stuff is (I think) file-wide, whereas in the notebook SVGs are inlined, so it's probably ignored. Looking at the file itself, even my browser's syntax highlighter sees the ]> as text, and not part of the markup. That said, the browser does still draw it correctly when viewed on its own.

This is another tic for using separate URLs for images, rather than inlining everything. Not all SVGs are going to be able to be inlined, and the code available for inlining is a subset of the code available to separate requests.

@ellisonbg
Member

Yes, the svg format has to be raw svg without all the document heading stuff.

@minrk
Member
minrk commented Aug 16, 2011

That's not clear enough, since there's no indication that we don't actually support regular SVG files.

When loading from a file, it should be easy to extract the svg tag, rather than the full xhtml document. Should we do that?

A simple example that works with the given file, at least:

from xml.dom import minidom
# parse full file into dom object
x = minidom.parseString(svg_src)
# get svg tag (should be 1)
found_svg = x.getElementsByTagName('svg')
if found_svg:
    real_svg = found_svg[0].toxml()
else:
    # there wasn't an svg in the file

Alternatively, the append_svg method could extract the actual svg tag:

minrk@a73f7c3

Either of these changes allows the example file to display properly

@minrk minrk added a commit that closed this issue Dec 11, 2011
@minrk minrk extract svg tag from svg files
We expect svg *tags*, not svg *documents*, which have headers, etc.
This lets the SVG DisplayObject extract the svg tag from a document,
so it works with regular svgs from a URL or file.

closes #700
5d96131
@minrk minrk closed this in 5d96131 Dec 11, 2011
@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
@minrk minrk extract svg tag from svg files
We expect svg *tags*, not svg *documents*, which have headers, etc.
This lets the SVG DisplayObject extract the svg tag from a document,
so it works with regular svgs from a URL or file.

closes #700
d1adc65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment