Disabling the "code" rule doesn't disable code parsing, just code rendering
Author: silvester-pariCreated Mar 4, 2024Updated Mar 5, 2024
When disabling the code rule, the default seems to be rendering a paragraph, no matter what the content is.
Setup
const md = markdownit();
md.disable('code')# This renders a heading
# This also renders a heading
# This renders a paragraph instead of a headingOutput
<h1>This renders a heading</h1>
<h1>This also renders a heading</h1>
<p># This renders a paragraph instead of a heading</p>This is because in the other rules there is also a "code block check", e.g. https://github.com/markdown-it/markdown-it/blob/master/lib/rules_block/heading.mjs#L10
// if it's indented more than 3 spaces, it should be a code block
if (state.sCount[startLine] - state.blkIndent >= 4) { return false }Question / Bug description
If I understand correctly, disabling the code rule just disables rendering of the code block, but not the code block parsing logic. Similar to the case with 2 spaces, I propose that disabling the code rule should skip the code block parsing in all other rules.
Background:
- https://github.com/markdown-it/markdown-it?tab=readme-ov-file#manage-rules
- https://github.com/markdown-it/markdown-it/blob/master/lib/parser_block.mjs
Might be connected to https://github.com/markdown-it/markdown-it/issues/936
Source: markdown-it/markdown-it