Skip to content

container directive do not work with fenced code blocks properly #25

Closed

Description

@DWaveletT

Initial checklist

Affected package

remark-directive@4.0.0

Steps to reproduce

When using remark-directive with containerDirective, nested directives inside fenced code blocks cause incorrect parsing. Specifically, the parser treats the inner ::: (inside a code block) as the closing marker for the outer container directive, leading to broken syntax trees and invalid output.

One way to solve it is to use a higher level outer container directive (for example, use four colons). However, the directiveToMarkdown plugin seems not able to recognize this problem and will produce three colons only, which will break the structure.

Actual behavior

Consider using this chain to parse markdown source code and stringify the mdast (which often used in code formatting):

unified()
  .use(remarkParse)
  .use(remarkDirective)
  .use(remarkStringify, { bullet: '-', rule: '-' })
  .process(content)

The input:

::::block
```markdown
:::block
some code
:::
```
::::

After processing, the output becomes:

:::block
```markdown
:::block
some code
:::
```
:::

This leads to incorrect rendering and broken nesting.

Expected behavior

Either parse the code block in the container directive properly, or produce proper result after using remarkStringify.

After processing and stringifying, the Markdown source should remain structurally unchanged.

::::block
```markdown
:::block
some code
:::
```
::::

Runtime

No response

Package manager

No response

Operating system

No response

Build and bundle tools

No response

Activity

  1. added
    👋 phase/newPost is being triaged automatically
    🤞 phase/openPost is being triaged manually
    and removed
    👋 phase/newPost is being triaged automatically
    on Jul 27, 2025
  2. wooorm commented on Jul 27, 2025

    @wooorm
    Member

    Ah interesting.
    That would go into mdast-util-directive. It should iterate over the internal lines, and not just look at nested deeper directives, but consider all lines that contain colons (and spaces and tabs) I think!

  3. wooorm commented on Oct 30, 2026

    @wooorm
    Member

    thanks, released in 3.2.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions