Skip to content

markdown-preferences/no-implicit-block-closing

disallow implicit block closing for fenced code blocks, math blocks, and custom containers

  • ⚙️ This rule is included in plugin.configs.recommended and plugin.configs.standard.
  • 🔧 The --fix option on the command line can automatically fix some of the problems reported by this rule.

📖 Rule Details

This rule disallows implicit block closing for fenced code blocks, math blocks, and custom containers in Markdown.
While Markdown allows blocks to be implicitly closed at the end of the document or when encountering certain other elements, explicit closing markers improve readability and prevent unintended content inclusion.

Note: Math blocks and custom containers are non-standard Markdown syntax. To use this rule with these extended syntaxes, you need to configure the "markdown-preferences/extended-syntax" language option in your ESLint configuration.

Why require explicit closing markers?

  • Improves code clarity and prevents ambiguity about where blocks end
  • Prevents accidentally including unintended trailing content in blocks
  • Makes it easier to understand the document structure
  • Ensures consistent behavior across different Markdown parsers
md
<!-- eslint markdown-preferences/no-implicit-block-closing: 'error' -->

<!-- ✓ GOOD -->

```js
console.log("hello");
```

> ```js
> console.log("hello");
> ```

<!-- ✗ BAD -->

> 
```
js
> console.log("hello");
```
js
console.log("hello");
md
<!-- eslint markdown-preferences/no-implicit-block-closing: 'error' -->

<!-- ✓ GOOD -->

::: warning
This is a warning block.
:::

<!-- ✗ BAD -->

:::
warning
This is a warning block. <!-- Missing closing marker -->
md
<!-- eslint markdown-preferences/no-implicit-block-closing: 'error' -->

<!-- ✓ GOOD -->

$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$

<!-- ✗ BAD -->

$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} <!-- Missing closing math block marker -->

🔧 Options

This rule has no options.

Configuration for Extended Syntax

To check math blocks and custom containers (which are non-standard Markdown syntax), you need to configure the "markdown-preferences/extended-syntax" language option:

js
// eslint.config.js
import { defineConfig } from "eslint/config";
import markdownPreferences from "eslint-plugin-markdown-preferences";

export default defineConfig([
  {
    extends: [markdownPreferences.configs.recommended],
    language: "markdown-preferences/extended-syntax",
    rules: {
      "markdown-preferences/no-implicit-block-closing": "error",
    },
  },
]);

📚 Further Reading

🚀 Version

This rule was introduced in eslint-plugin-markdown-preferences v0.28.0

🔍 Implementation