Skip to content
This repository

Some SVG images render incorrectly in htmlnotebook #700

Closed
stefanv opened this Issue · 3 comments

3 participants

Stefan van der Walt Min RK Brian E. Granger
Stefan van der Walt

When displaying this SVG file in the htmlnotebook:

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

The output is "]>" + image.

Min RK
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.

Brian E. Granger
Owner

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

Min RK
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

Min RK minrk closed this issue from a commit
Min RK 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
Min RK minrk closed this in 5d96131
Brian E. Granger ellisonbg referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
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.