Skip to content

fix: fenced code block indentation#143

Open
adamdehaven wants to merge 1 commit intonuxt-content:mainfrom
adamdehaven:fix/fenced-code-block-indentation
Open

fix: fenced code block indentation#143
adamdehaven wants to merge 1 commit intonuxt-content:mainfrom
adamdehaven:fix/fenced-code-block-indentation

Conversation

@adamdehaven
Copy link
Copy Markdown

@adamdehaven adamdehaven commented May 7, 2026

Summary

Note

@farnabaz this will need to be picked up in @nuxtjs/mdc once verified and released.

Fixes a bug where a fenced code block at column 0 inside a MDC block component had its content indentation stripped when an indented child component appeared earlier in the same container block.

Resolves nuxt-content/mdc#483

Reproduction

Paste the following into the https://github.com/nuxt-content/mdc playground (dev server)

::container

  ::container
  ---
  foo: "bar"
  ---
  ::

```json
{
  "labore": "set dolore",
  "magna": "aliqua",
  "veniam": true
}
```

::
image

The ::container at 2-space indent causes the tokenizer to set containerIndentSize = 2. From that point on, dentendIndentedCommponent and attemptIntentedCommponent were unconditionally calling factorySpace to strip up to containerIndentSize + 1 spaces from every subsequent line, including lines inside a code fence that was opened at column 0. The guard against visitingCodeFenced happened inside lineStartAfterPrefix, which is called after the spaces were already consumed.

Fix

Track whether the current fence's opening line itself had spaces stripped (codeFenceStripped).

When visitingCodeFenced && !codeFenceStripped, skip the factorySpace call entirely so code content at column 0 is passed through untouched. Fences opened at containerIndentSize indent (e.g. yaml props blocks) continue to work correctly since their opening lines do go through stripping.

@adamdehaven adamdehaven force-pushed the fix/fenced-code-block-indentation branch from 87a9194 to efb7275 Compare May 7, 2026 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fenced code blocks inside of a block component lose their top-level indentation

1 participant