Skip to content
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

Description

@lijunle

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions