Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Prepend doctype only when it is HTML #53

Open
lijunle opened this issue Oct 21, 2015 · 1 comment
Open

Prepend doctype only when it is HTML #53

lijunle opened this issue Oct 21, 2015 · 1 comment

Comments

@lijunle
Copy link
Contributor

lijunle commented Oct 21, 2015

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!

lijunle added a commit to depcheck/depcheck-www that referenced this issue Oct 21, 2015
- Hack the React view engine to support SVG, see
  reactjs/express-react-views#53
@lijunle
Copy link
Contributor Author

lijunle commented Oct 22, 2015

/cc @zpao

I could like to help to send a RP if you think this is OK.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant