Skip to content

Bug: Nested fenced code blocks (4 backticks) are corrupted #8109

@oscarvdl

Description

@oscarvdl

Lexical version: indirect dependency (version not exposed by Sveltia CMS)

Steps To Reproduce

  1. Create or edit a markdown document in the Sveltia CMS editor.
  2. Switch to markdown view.
  3. Add nested fenced code blocks using 4 backticks to wrap content that contains a 3-backtick code block, e.g.:
````markdown
## Development Setup

After cloning, run:

```bash
pip install pre-commit
pre-commit install
```
````
  1. Save the markdown content.
  2. Close the editor.
  3. Reopen the same markdown document in the editor.
  4. Observe the malformed markdown output.

Link to code example: https://playground.lexical.dev/#doc=H4sIAAAAAAAACtWVwW7CMAyGX6Uy14DKhtYtt0l7gEnsNk1qaEwbkTpV6rAh1HefUjYGnBCMiZ0S_7F_f744a0Bt2PkpK0aQa_DOcTyLyljtkUC-HgQaWRkLMhUwd75W3F9rpxEkUFQsCGh5ZaMAAhg_GCTkeR6DVRPlwmkcVqasrCkrBgFL9K1xBHIsYKu_bJKbQAUHxfG9E2cQ1MovtHunEzn6ZKuoDKrEnuTLxRrCmUe12DM4B3UwSJ5widY1NRInU-TQnEM9s65YHId8sZke54w-KawjQ6VIfCD530fK83ym2uqPxjiVsjFNYqhlZW3SeBwWrq4NXzv0FvSb_cqBf2-_XRLxOMbuTYA2HoueSVKw9qdVNDSkkTZtd9wO5tyuSgnbzXuCc_8l7dF10bvlqVqiBjnOsjSdZHc3k_txJqB1wRex7tmqVeldIL1bDeno9mGUQvcJoRgyfvsGAAA

Click the Convert from Markdown button

The current behavior

When reopening a document that contains nested fenced code blocks (4 backticks wrapping a 3-backtick fenced block), the editor corrupts the structure: it misinterprets and breaks the nesting boundaries, leading to malformed markdown where code blocks are opened/closed incorrectly.

The expected behavior

The nested fenced code block structure should be preserved exactly as it was entered, with the outer 4-backtick fence correctly containing the inner 3-backtick code block, following CommonMark rules for nested fences.

Impact of fix

Severity: High for users documenting examples of code within markdown (e.g., docs, tutorials).

Frequency: Happens whenever nested code fences are used and the document is reopened.

Who would benefit: Content authors using advanced markdown features; anyone relying on accurate editing of code examples.

Metrics (if known): Affects all markdown fields in the CMS editor where nested code blocks are used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions