Skip to content

Commit

Permalink
Merge pull request #6469 from zerline/issue#6295
Browse files Browse the repository at this point in the history
SVG namespace. Fixes #6295.
  • Loading branch information
jasongrout committed Jun 6, 2019
2 parents cf98435 + 877075b commit ebadf8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/rendermime/src/renderers.ts
Expand Up @@ -418,6 +418,12 @@ export function renderSVG(options: renderSVG.IRenderOptions): Promise<void> {
return Promise.resolve(undefined);
}

// Add missing SVG namespace (if actually missing)
let patt = '<svg[^>]+xmlns=[^>]+svg';
if (source.search(patt) < 0) {
source = source.replace('<svg', '<svg xmlns="http://www.w3.org/2000/svg"');
}

// Render in img so that user can save it easily
const img = new Image();
img.src = `data:image/svg+xml,${encodeURIComponent(source)}`;
Expand Down
3 changes: 2 additions & 1 deletion tests/test-rendermime/src/factories.spec.ts
Expand Up @@ -135,14 +135,15 @@ describe('rendermime/factories', () => {
describe('#createRenderer()', () => {
it('should create an img element with the uri encoded svg inline', async () => {
const source = '<svg></svg>';
const displaySource = '<svg xmlns="http://www.w3.org/2000/svg"></svg>';
const f = svgRendererFactory;
const mimeType = 'image/svg+xml';
const model = createModel(mimeType, source, true);
const w = f.createRenderer({ mimeType, ...defaultOptions });
await w.renderModel(model);
const imgEl = w.node.getElementsByTagName('img')[0];
expect(imgEl).to.be.ok;
expect(imgEl.src).to.contain(encodeURIComponent(source));
expect(imgEl.src).to.contain(encodeURIComponent(displaySource));
});
});
});
Expand Down

0 comments on commit ebadf8e

Please sign in to comment.