How to use web-namespaces - 10 common examples

To help you get started, we’ve selected a few web-namespaces 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 / index.js View on Github external
const { children = [] } = node;
  const { length: childrenLength } = children;

  let namespace = optionsNamespace;
  let rootIsDocument = childrenLength === 0;

  for (let i = 0; i < childrenLength; i += 1) {
    const { tagName, properties = {} } = children[i];

    if (tagName === 'html') {
      // If we have a root HTML node, we don’t need to render as a fragment.
      rootIsDocument = true;

      // Take namespace of the first child.
      if (typeof optionsNamespace === 'undefined') {
        namespace = properties.xmlns || ns.html;
      }
    }
  }

  // The root node will be a Document, DocumentFragment, or HTMLElement.
  let el;

  if (rootIsDocument) {
    el = doc.implementation.createDocument(namespace, '', null);
  } else if (fragment) {
    el = doc.createDocumentFragment();
  } else {
    el = doc.createElement('html');
  }

  return appendAll(
github rehypejs / rehype-dom / packages / rehype-dom-stringify / src / index.js View on Github external
import xtend from 'xtend';
import toDOM from 'hast-util-to-dom';
import ns from 'web-namespaces';

const htmlXmlnsExpression = new RegExp(` xmlns="${ns.html}"`, 'g');

export default function stringify(config) {
  const settings = xtend(config, this.data('settings'));

  if (settings.fragment == null) {
    settings.fragment = true;
  }

  this.Compiler = compiler;

  function compiler(tree) {
    const node = toDOM(tree, settings);
    const serialized = new XMLSerializer().serializeToString(node);

    // XMLSerializer puts xmlns on root elements (typically the document
    // element, but in case of a fragment all of the fragments children).
github syntax-tree / hast-util-to-dom / src / utils.js View on Github external
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');
}
github syntax-tree / hast-util-to-dom / src / index.js View on Github external
function element(node, options) {
  const { namespace, doc } = options;
  let impliedNamespace = options.impliedNamespace || namespace;
  const { tagName = impliedNamespace === ns.svg ? 'g' : 'div', properties = {}, children = [] } = node;

  if (
    (impliedNamespace === null || impliedNamespace === undefined || impliedNamespace === ns.html)
    && tagName === 'svg'
  ) {
    impliedNamespace = ns.svg;
  }

  const schema = impliedNamespace === ns.svg ? svg : html;

  const el = impliedNamespace === null || impliedNamespace === undefined
    ? doc.createElement(tagName)
    : doc.createElementNS(impliedNamespace, tagName);

  // Add HTML attributes.
  const props = Object.keys(properties);
  const { length } = props;

  for (let i = 0; i < length; i += 1) {
github adobe / helix-pipeline / src / utils / hast-util-to-dom.js View on Github external
const { children = [] } = node;
    const { length: childrenLength } = children;

    let namespace = optionsNamespace;
    let rootIsDocument = childrenLength === 0;

    for (let i = 0; i < childrenLength; i += 1) {
      const { tagName, properties = {} } = children[i];

      if (tagName === 'html') {
        // If we have a root HTML node, we don’t need to render as a fragment.
        rootIsDocument = true;

        // Take namespace of the first child.
        if (typeof optionsNamespace === 'undefined') {
          namespace = properties.xmlns || ns.html;
        }
      }
    }

    // The root node will be a Document, DocumentFragment, or HTMLElement.
    let el;

    if (rootIsDocument) {
      el = document.implementation.createDocument(namespace, '', null);
    } else if (fragment) {
      el = document.createDocumentFragment();
    } else {
      el = document.createElement('html');
    }

    return appendAll(el, children, { fragment, namespace, ...options });
github syntax-tree / hast-util-to-dom / src / utils.js View on Github external
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');
}
github syntax-tree / hast-util-to-dom / src / index.js View on Github external
function element(node, options) {
  const { namespace, doc } = options;
  let impliedNamespace = options.impliedNamespace || namespace;
  const { tagName = impliedNamespace === ns.svg ? 'g' : 'div', properties = {}, children = [] } = node;

  if (
    (impliedNamespace === null || impliedNamespace === undefined || impliedNamespace === ns.html)
    && tagName === 'svg'
  ) {
    impliedNamespace = ns.svg;
  }

  const schema = impliedNamespace === ns.svg ? svg : html;

  const el = impliedNamespace === null || impliedNamespace === undefined
    ? doc.createElement(tagName)
    : doc.createElementNS(impliedNamespace, tagName);

  // Add HTML attributes.
  const props = Object.keys(properties);
github Prettyhtml / prettyhtml / packages / prettyhtml-hast-util-from-parse / index.js View on Github external
var fn = own.call(map, ast.nodeName) ? map[ast.nodeName] : element
  var children
  var node
  var pos

  // remove #document-fragment and update parentNode of childs
  if (ast.nodeName === 'template') {
    ast.childNodes = ast.content.childNodes
    ast.childNodes.forEach(n => {
      n.parentNode = ast
    })
    delete ast.content
  }

  if (fn === element) {
    config.schema = ast.namespaceURI === ns.svg ? svg : html
  }

  if (ast.childNodes) {
    children = nodes(ast.childNodes, config)
  }

  node = fn(ast, children, config)

  if (ast.sourceCodeLocation && config.file) {
    pos = location(node, ast.sourceCodeLocation, config)

    if (pos) {
      config.location = true
      node.position = pos
    }
  }
github syntax-tree / hast-util-to-dom / src / index.js View on Github external
function element(node, options) {
  const { namespace, doc } = options;
  let impliedNamespace = options.impliedNamespace || namespace;
  const { tagName = impliedNamespace === ns.svg ? 'g' : 'div', properties = {}, children = [] } = node;

  if (
    (impliedNamespace === null || impliedNamespace === undefined || impliedNamespace === ns.html)
    && tagName === 'svg'
  ) {
    impliedNamespace = ns.svg;
  }

  const schema = impliedNamespace === ns.svg ? svg : html;

  const el = impliedNamespace === null || impliedNamespace === undefined
    ? doc.createElement(tagName)
    : doc.createElementNS(impliedNamespace, tagName);

  // Add HTML attributes.
  const props = Object.keys(properties);
  const { length } = props;

  for (let i = 0; i < length; i += 1) {
    const key = props[i];

    const {
github syntax-tree / hast-util-to-dom / src / index.js View on Github external
function element(node, options) {
  const { namespace, doc } = options;
  let impliedNamespace = options.impliedNamespace || namespace;
  const { tagName = impliedNamespace === ns.svg ? 'g' : 'div', properties = {}, children = [] } = node;

  if (
    (impliedNamespace === null || impliedNamespace === undefined || impliedNamespace === ns.html)
    && tagName === 'svg'
  ) {
    impliedNamespace = ns.svg;
  }

  const schema = impliedNamespace === ns.svg ? svg : html;

  const el = impliedNamespace === null || impliedNamespace === undefined
    ? doc.createElement(tagName)
    : doc.createElementNS(impliedNamespace, tagName);

  // Add HTML attributes.
  const props = Object.keys(properties);
  const { length } = props;

  for (let i = 0; i < length; i += 1) {
    const key = props[i];

    const {
      attribute,
      property,
      // `mustUseAttribute`,

web-namespaces

Map of web namespaces

MIT
Latest version published 3 years ago

Package Health Score

65 / 100
Full package analysis

Popular web-namespaces functions