Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Some SVG images render incorrectly in htmlnotebook #700

Closed
stefanv opened this Issue · 3 comments

3 participants

@stefanv

When displaying this SVG file in the htmlnotebook:

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

The output is "]>" + image.

@minrk
Owner

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
Owner

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

@minrk
Owner

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 closed this issue from a commit
@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
@ellisonbg ellisonbg referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@mattvonrocketstein mattvonrocketstein referenced this issue from a commit in mattvonrocketstein/ipython
@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
Something went wrong with that request. Please try again.