Skip to content

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

@DWaveletT

Description

@DWaveletT

Initial checklist

Affected package

[email protected]

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    🤞 phase/openPost is being triaged manually

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions