How to use the w3c-xmlserializer.XMLSerializer.interface function in w3c-xmlserializer

To help you get started, we’ve selected a few w3c-xmlserializer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github syntax-tree / hast-util-to-dom / src / utils.js View on Github external
import ns from 'web-namespaces';
// eslint-disable-next-line import/no-extraneous-dependencies
import { XMLSerializer as Serializer } from 'w3c-xmlserializer';

const XMLSerializer = Serializer.interface;

export default function serializeNodeToHtmlString(node) {
  const serialized = new XMLSerializer().serializeToString(node);

  // XMLSerializer puts xmlns on “main” elements that are not in the XML
  // namespace.
  // We’d like to inspect that, but having the HTML namespace everywhere will
  // get unwieldy, so remove those.
  return serialized
    .replace(new RegExp(` xmlns="${ns.html}"`, 'g'), '')
    .replace(new RegExp(`(<(?:svg|g)) xmlns="${ns.svg}"`, 'g'), '$1');
}

w3c-xmlserializer

A per-spec XML serializer implementation

MIT
Latest version published 12 months ago

Package Health Score

72 / 100
Full package analysis