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">HTML element div is not allowed.
Press <kbd>HTML element kbd is not allowed.Enter</kbd>.
</div>example.mdNo problems
Press **Enter**.
<!-- A comment -->Options#
| Option | Default | What it does |
|---|---|---|
allowed | [] | The names of the elements that are allowed. |
allowedIgnoreCase | false | Ignore case, so KBD is allowed if kbd is on the list. |
example.mdwith
{ "allowed": ["kbd"] }No problemsPress <kbd>Enter</kbd>.example.mdwith
{ "allowed": ["kbd"] }1 problemPress <KBD>HTML element KBD is not allowed.Enter</KBD>.example.mdwith
{ "allowed": ["kbd"], "allowedIgnoreCase": true }No problemsPress <KBD>Enter</KBD>.