0.0.1 • Published 2 years ago

eslint-parser-mdast v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

eslint-parser-mdast

An ESLint custom parser for generating markdown abstract syntax trees (in this case - mdast). Uses mdast-util-from-markdown under the hood.

Unlike a usual custom parser which parses JS files, this receives input from markdown (.md) files.

This means that the Program node returned as part of the JS abstract syntax tree (AST) contains mostly dummy values, except for its property markdown which returns Root.

Usage

  1. Install package as a dev dependency:
yarn add -D eslint-parser-mdast
  1. Include parser in your .eslintrc config:
// .eslintrc
module.exports = {
  overrides: {
    '*.md': {
      parser: 'eslint-parser-mdast',
    },
  },
}
  1. Retrieve mdast in your custom ESLint plugin rule:
// src > rules > myCustomRule.js
module.exports = {
  meta: { ... },
  create: function(context) {
    return {
      Program(node) {
        // retrieve `mdast` with `node.markdown` here
      }
    }
  }
}