markdown/no-html

Disallow HTML tags

Markdown passes HTML through unchanged, but not every renderer does: some strip it, some escape it, and MDX reads it as JSX. This rule limits a document to plain Markdown, or to a short list of allowed elements.

Each opening tag is reported. Closing tags and comments are not.

Configure#

Off by default. It needs an ESLint config that says which files are in the language:

eslint.config.js
import markdown from "@eslint/markdown";

export default [
  {
    files: ["**/*.md"],
    plugins: { markdown },
    language: "markdown/commonmark",
    rules: { "markdown/no-html": "error" },
  },
];

It also works with markdown/gfm.

Examples#

example.md2 problems
<div align="center">

Press <kbd>Enter</kbd>.

</div>
example.mdNo problems
Press **Enter**.

<!-- A comment -->

Options#

OptionDefaultWhat it does
allowed[]The names of the elements that are allowed.
allowedIgnoreCasefalseIgnore case, so KBD is allowed if kbd is on the list.
example.mdwith { "allowed": ["kbd"] }No problems
Press <kbd>Enter</kbd>.
example.mdwith { "allowed": ["kbd"] }1 problem
Press <KBD>Enter</KBD>.
example.mdwith { "allowed": ["kbd"], "allowedIgnoreCase": true }No problems
Press <KBD>Enter</KBD>.