The simplest abstract syntax tree walker.
npm install @lint-md/ast-pluginjs
import { Ast, Plugin } from 'ast-plugin';
new Ast(ast).traverse([
new TestPlugin(cfg),
// ...
]);
`
- Write an ast plugin
`js
import { Ast, Plugin } from 'ast-plugin';
class TestPlugin extends Plugin {
pre = () => {
};
visitor = () => {
return {
// process node with type = 'text'
text: ast => {
console.log(ast.node);
ast.segment();
},
};
};
post = () => {
};
}
``