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

javascript
const md = markdownit();
md.disable('code')
markdown
# This renders a heading

  # This also renders a heading

    # This renders a paragraph instead of a heading

Output

xml
<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:

Might be connected to https://github.com/markdown-it/markdown-it/issues/936