An ESLint plugin to lint JavaScript in Markdown code fences.
Last updated 3 years ago by tolmasky .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install eslint-plugin-markdown-runkit 
SYNC missed versions from official npm registry.



An ESLint plugin to lint JavaScript in Markdown.

Supported extensions are .markdown, .mdown, .mkdn, and .md.


Install the plugin:

npm install --save-dev eslint eslint-plugin-markdown

Add it to your .eslintrc:

    "plugins": [

Run ESLint on .md files:

eslint --ext md .

It will lint js, javascript, jsx, or node fenced code blocks in your Markdown documents:

// This gets linted
var answer = 6 * 7;

// This also gets linted

/* eslint quotes: [2, "double"] */

function hello() {
    console.log("Hello, world!");

// This gets linted too
var div = <div className="jsx"></div>;

// And this

Blocks that don't specify either js, javascript, jsx, or node syntax are ignored:

This is plain text and doesn't get linted.

print("This doesn't get linted either.")

Configuration Comments

The processor will convert HTML comments immediately preceding a code block into JavaScript block comments and insert them at the beginning of the source code that it passes to ESLint. This permits configuring ESLint via configuration comments while keeping the configuration comments themselves hidden when the markdown is rendered. Comment bodies are passed through unmodified, so the plugin supports any configuration comments supported by ESLint itself.

This example enables the browser environment, disables the no-alert rule, and configures the quotes rule to prefer single quotes:

<!-- eslint-env browser -->
<!-- eslint-disable no-alert -->
<!-- eslint quotes: ["error", "single"] -->

alert('Hello, world!');

Each code block in a file is linted separately, so configuration comments apply only to the code block that immediately follows.

Assuming `no-alert` is enabled in `.eslintrc`, the first code block will have no error from `no-alert`:

<!-- eslint-env browser -->
<!-- eslint-disable no-alert -->

alert("Hello, world!");

But the next code block will have an error from `no-alert`:

<!-- eslint-env browser -->

alert("Hello, world!");

Skipping Blocks

Sometimes it can be useful to have code blocks marked with js even though they don't contain valid JavaScript syntax, such as commented JSON blobs that need js syntax highlighting. Standard eslint-disable comments only silence rule reporting, but ESLint still reports any syntax errors it finds. In cases where a code block should not even be parsed, insert a non-standard <!-- eslint-skip --> comment before the block, and this plugin will hide the following block from ESLint. Neither rule nor syntax errors will be reported.

There are comments in this JSON, so we use `js` syntax for better
highlighting. Skip the block to prevent warnings about invalid syntax.

<!-- eslint-skip -->

    // This code block is hidden from ESLint.
    "hello": "world"

console.log("This code block is linted normally.");

Unsatisfiable Rules

Since code blocks are not files themselves but embedded inside a Markdown document, some rules do not apply to Markdown code blocks, and messages from these rules are automatically suppressed:

  • eol-last
  • unicode-bom


The strict rule is technically satisfiable inside of Markdown code blocks, but writing a "use strict" directive at the top of every code block is tedious and distracting. We recommend using a glob pattern override for .md files to disable strict and enable the impliedStrict parser option so the code blocks still parse in strict mode:

// .eslintrc.json
    // ...
    "overrides": [{
        "files": ["**/*.md"],
        "parserOptions": {
            "ecmaFeatures": {
                "impliedStrict": true
        "rules": {
            "strict": "off"


$ git clone
$ cd eslint-plugin-markdown
$ npm install
$ npm test

This project follows the ESLint contribution guidelines.

Current Tags

  • 1.0.0-beta.8                                ...           latest (3 years ago)

1 Versions

  • 1.0.0-beta.8                                ...           3 years ago
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (6)
Dependents (0)

Copyright 2014 - 2021 © |