How to use the posthtml/lib/api.walk function in posthtml

To help you get started, we’ve selected a few posthtml 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 codesandbox / codesandbox-client / packages / app / src / sandbox / eval / presets / parcel / transpilers / html-worker.js View on Github external
}

    function addSrcSetDependencies(srcset: string) {
      const newSources = [];

      srcset.split(',').forEach(source => {
        const pair = source.trim().split(' ');
        if (pair.length === 0) return;
        pair[0] = addDependency(pair[0]);
        newSources.push(pair.join(' '));
      });
      return newSources.join(',');
    }

    const res = parse(code, { lowerCaseAttributeNames: true });
    res.walk = api.walk;
    res.match = api.match;

    res.walk(node => {
      if (node == null) {
        return node;
      }

      if (node.attrs) {
        if (node.tag === 'meta') {
          if (
            !Object.keys(node.attrs).some(attr => {
              const values = META[attr];
              return values && values.includes(node.attrs[attr]);
            })
          ) {
            return node;
github roman01la / html-to-react-components / lib / processor.js View on Github external
if (
    componentType !== "stateless" &&
    componentType !== "es5" &&
    componentType !== "es6"
  ) {
    componentType = "es6";
  }

  if (moduleType !== "es6" && moduleType !== "cjs") {
    moduleType = "es6";
  }

  var components = [];
  var delimiter = options.moduleFileNameDelimiter || "";

  api.walk.bind(tree)(collectComponents(components));

  var reactComponents = toReactComponents(
    componentType,
    toJsxAST(
      mergeByInstance(
        components.map(assignByName).map(clearAndRenderComponents)
      )
    )
  );

  if (moduleType) {
    return formatCode(
      toCode(toModules(moduleType, delimiter, reactComponents))
    );
  }
github parcel-bundler / parcel / packages / core / parcel-bundler / src / assets / HTMLAsset.js View on Github external
async parse(code) {
    let res = await posthtmlTransform.parse(code, this);
    res.walk = api.walk;
    res.match = api.match;
    return res;
  }
github kevinkace / posthtml-pseudo / lib / classNameFunctions / default.js View on Github external
"use strict";

const walk = require("posthtml/lib/api").walk,
    get    = require("lodash/get"),

    addClassNameToNode = require("../addClassNameToNode"),

    eligibleTags = [
        "button",
        "input"
    ],
    className = ":default";

module.exports = function(node) {
    let test = false;

    if(!node.tag || node.tag !== "form" || !node.content.length) {
        return node;
    }
github parcel-bundler / parcel / src / transforms / html / src / HTMLAsset.js View on Github external
async parse(code) {
    let res = await posthtmlTransform.parse(code, this);
    res.walk = api.walk;
    res.match = api.match;
    return res;
  }
github roman01la / html-to-react-components / index.js View on Github external
function childrenToComponent(component) {

  var children = [];

  api.walk.bind(component)(function(node) {

    if (isComponent(node)) {

      var name = getComponentName(node);

      children.push(name);

      return {
        tag: name
      };
    }

    return toJsxAttrs(node);
  });

  return {