Skip to content

outline-minor-mode folds # comments inside fenced code blocks in markdown-mode #915

@jamescherti

Description

@jamescherti

outline-minor-mode folds # comments inside fenced code blocks ```.

Expected Behavior

When outline-minor-mode is enabled in markdown-mode, only actual Markdown headings (lines starting with # outside of fenced code blocks) should be folded or treated as outline entries. Lines inside code blocks, even if they start with #, should be ignored by the outline engine.

Actual Behavior

Lines starting with # inside fenced code blocks are incorrectly recognized as headings by outline-minor-mode. As a result, such lines are included in outline folding and navigation, even though they are part of literal code content.

This leads to incorrect and confusing folding behavior when editing Markdown files with embedded code snippets.

Steps to Reproduce

  1. Open a Markdown buffer in Emacs.
  2. Enable outline-minor-mode.
  3. Insert the following content:
# Top-level Heading

```python
# This should not be folded
def foo():
    pass
```

## Subheading
  1. Move the cursor to # This should not be folded and run M-x outline-hide-sublevels.

Observed: The line # This should not be folded inside the Python code block is treated as an outline heading and is foldable.

Expected: The content inside the code block should be ignored by the outline engine. Only real Markdown headings outside of code blocks should be recognized.

This behavior makes outline-minor-mode unusable in practical Markdown editing workflows where fenced code blocks are common.

Software Versions

  • Markdown 7eb8305
  • Emacs: 30.1
  • OS: Arch Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions