Skip to content

The simplest abstract syntax tree walker, similar with @babel plugin.

Notifications You must be signed in to change notification settings

lint-md/ast-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@lint-md/ast-plugin

The simplest abstract syntax tree walker.

Build Status

Install

npm i --save ast-plugin

Usage

  • Traverse Ast plugins
import { Ast, Plugin } from 'ast-plugin';

new Ast(ast).traverse([
  new TestPlugin(cfg),
  // ...
]);
  • Write an ast plugin
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 = () => {
  };
}

Used by

  • lint-md Cli tool to lint your markdown file for Chinese.

License

MIT@hustcc.