This repository was archived by the owner on Feb 1, 2022. It is now read-only.
This repository was archived by the owner on Feb 1, 2022. It is now read-only.
Prepend doctype only when it is HTML #53
Open
Description
I am using React and Express to render SVG. The generated string is something like <svg>...</svg>
.
- It is not a HTML, do not prepend doctype in front of the string.
- The SVG is the root element, it needs one more
xmlns
attribute to tell browser to render this SVG:xmlns="http://www.w3.org/2000/svg"
.
Currently, I hack the viewEngine callback as a workaround:
const viewEngine = react.createEngine({ transformViews: false });
app.engine('js', (filePath, options, callback) => {
return viewEngine(filePath, options, (error, html) => {
const raw = html.substring('<!DOCTYPE html>'.length);
const hack = raw.indexOf('<svg') === 0
? raw.replace('<svg', '<svg xmlns="http://www.w3.org/2000/svg"')
: html;
callback(error, hack);
});
});
Hope this package could handle it. Thanks!
Metadata
Metadata
Assignees
Labels
No labels