How to use domutils - 10 common examples

To help you get started, we’ve selected a few domutils 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 jbhannah / amperize / lib / amperize.js View on Github external
if (!element.attribs.layout) {
                setLayoutAttribute(element);
            }
        }
    }



    // convert all of the img elements first so that we can perform lengthy
    // network requests in parallel before sequentially traversing the DOM
    if (self.config['amp-img']) {
        var imgTest = function(elem) {
            return elem.name === 'img' && elem.attribs.src;
        }
        var imgElems = domutils.findAll(elem => imgTest(elem), data);
        var imgTasks = imgElems.map(elem => amperizeImageElem(elem));
        await async.parallelLimit(imgTasks, 10);
    }

    // sequentially traverse the DOM
    async.reduce(data, html, function reduce(html, element, step) {
        var children;

        if (/(style|script|textarea|link)/.test(element.name)) {
            return step(null, html);
        }

        function close(error, html) {
            html += helpers.close(element);
            step(null, html);
        }
github superfly / fly / packages / v8env / src / document.ts View on Github external
public appendChild(html) {
    if (typeof html._dom !== "undefined") {
      // Document
      if (Array.isArray(this._dom)) {
        appendChild(this._dom[1], html._dom)
      } else {
        appendChild(this._dom, html._dom)
      }
      return html
    }
    html = new Element(parseDOMSync(html)[0])
    return this.appendChild(html)
  }
}
github superfly / fly / packages / v8env / src / document.ts View on Github external
public appendChild(html) {
    if (typeof html._dom !== "undefined") {
      // Document
      if (Array.isArray(this._dom)) {
        appendChild(this._dom[1], html._dom)
      } else {
        appendChild(this._dom, html._dom)
      }
      return html
    }
    html = new Element(parseDOMSync(html)[0])
    return this.appendChild(html)
  }
}
github ReactiveSets / toubkal / lib / html / html_serialize.js View on Github external
return source.alter( function( value ) {
      try {
        de&&ug( value.dom );
        
        value.content = serialize( value.dom );
      } catch( e ) {
        value.error   = e;
        value.content = null;
      }
    } );
  } ); // html_serialize()
github Janpot / microdata-node / lib / microdataDom.js View on Github external
module.exports = function (dom, config) {
  config = config || {};

  // resolve the base url of the document
  var base = config.base || '';
  var baseElem = DOM.findOne(function (elem) {
    return elem.name === 'base' && DOM.hasAttrib(elem, 'href');
  }, dom);
  if (baseElem) {
    base = urlUtil.resolve(base, baseElem.attribs.href);
  }

  var strict = config.strict;

  var idMap = mapIds(dom);

  function _getItems (nodes, isTopLevel) {
    var items = [];
    nodes.forEach(function (node) {
      var childIsTopLEvel = isTopLevel;
      var isStrictItem = isItem(node) && !isProperty(node);
      var isNonStrictItem = isItem(node) && isTopLevel;
github fb55 / css-select / test / sizzle / selector.js View on Github external
dom.forEach(function(child) {
                DomUtils.appendChild(elem, child);
            });
            return this;
github fb55 / css-select / test / sizzle / selector.js View on Github external
helper.getDOM(str).forEach(function(child) {
                    DomUtils.prepend(elem, child);
                });
            });
github ctx-core / ctx-core / packages / fontawesome / bin / refresh-font-awesome.js View on Github external
const handler = new DomHandler((error, dom) => {
				if (error) {
					throw error
				} else {
					const { attribs } = dom[0]
					const { viewbox } = attribs
					const [width, height] = viewbox.split(/ +/g).slice(2)
					assign(attribs, { width, height })
					html = `
${getInnerHTML(dom[0])}
					`.trim()
				}
			})
			const parser = new Parser(handler)
github fb55 / htmlparser2 / lib / FeedHandler.js View on Github external
function getOneElement(what, where) {
    return DomUtils.getElementsByTagName(what, where, true, 1)[0];
}
function fetch(what, where, recurse) {
github broadly / css-inliner / lib / add_rules.js View on Github external
function bodyElement(dom) {
  return DOMUtils.getElementsByTagName('body', dom, true, 2)[0];
}