How to use the idyll-ast.modifyChildren function in idyll-ast

To help you get started, we’ve selected a few idyll-ast 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 DefinitelyTyped / DefinitelyTyped / types / idyll-ast / idyll-ast-tests.ts View on Github external
// $ExpectType TreeNode
createNode("div", { prop1: "prop1", prop2: ["expression", "x=2"] }, []);

// $ExpectType Node[]
getChildren(ast[0]);

// $ExpectType void
walkNodes(ast, (n: Node) => {
    (n as TreeNode)[0] = "funky-name";
});

// $ExpectType Node[]
findNodes(ast, n => n instanceof Array);

// $ExpectType Node
modifyChildren(ast[0], (n: Node) => {
    if (typeof n === "object") {
        n[0] = "somename";
    }
});
// $ExpectType Node[]
getNodesByName(ast, "h1");

// $ExpectType Node
filterChildren(ast[1], n => n === "world");

// $ExpectType Node[] || AST
filterNodes(ast, n => (n instanceof Object ? n[0] === "h1" : false));

// $ExpectType Node[] || AST
modifyNodesByName(ast, "h2", n => {
    typeof n === "object" ? (n[1] = []) : undefined;
github idyll-lang / idyll-studio / src / components / idyll-document / src / runtime.js View on Github external
return node;
        }
        var id = IdyllAST.getProperty(node, 'id');
        if(id === undefined) {
          return node;
        }
        var compare = id[1] === key
        // console.log('id[1]',id[1],'key',key,compare)
        if( compare ) {
          console.log('mod block')
          found = true;
          return newNode;
          
        }
    
        node = IdyllAST.modifyChildren(node, handleNode);
        return node;
      }
github idyll-lang / idyll / packages / idyll-compiler / src / processors / post.js View on Github external
return modifyNodesByName(ast, 'TextContainer', (node) => {
    return modifyChildren(node, (child) => {
      if (typeof child === 'string') {
        return ['p', [], [child]];
      }
      return child;
    })
  })
};
github idyll-lang / idyll / packages / idyll-compiler / src / processors / post.js View on Github external
function autoLinkifyHelper(node) {
  if(typeof node === 'string') {
    return hyperLinkifiedVersion(node); 
  } else if (['a', 'code', 'pre', 'equation'].indexOf(getNodeName(node).toLowerCase()) > -1){
    return node; 
  } else {
    return modifyChildren(node, autoLinkifyHelper); 
  }
}