Skip to content

Fix container fence when content has a line of colons - #18

Closed
builtbysharath wants to merge 1 commit into
syntax-tree:mainfrom
builtbysharath:fix-fence-colon-lines
Closed

builtbysharath wants to merge 1 commit into
syntax-tree:mainfrom
builtbysharath:fix-fence-colon-lines

Conversation

@builtbysharath

Copy link
Copy Markdown
Contributor

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything or linked relevant results below
  • I made sure the docs are up to date
  • I included tests (or that’s not needed)

Description of changes

Closes remarkjs/remark-directive#25.

The fence of a container directive was sized only from the container directives nested in it. A line of colons elsewhere in the content, such as ::: in fenced code, also closes the container when it has at least as many colons as the fence. So this round trip:

::::a
```markdown
:::b
c
:::
```
::::

was serialized with a ::: fence, which the ::: line in the code then closes.

As suggested in remarkjs/remark-directive#25 (comment), the container now looks at the lines of its serialized content. It makes the fence longer than the longest sequence of colons on any line that has only spaces and tabs around it, which is what micromark accepts as a closing fence. Lines with colons and other characters, such as :::b, can't close the container and don't change the fence. The nesting count is kept, so output for nested containers, including those in block quotes, is unchanged. Because the lines are those of the serialized content, an inner container whose fence grew pushes the outer fence up too.

The content has to be serialized before the fence size is known, so when the fence grows, the extra colons are prepended to the opening afterwards. The tracker position given to the label doesn't include those extra colons.

Tests cover code with a line of colons, colons with spaces and tabs around them, colons followed by other characters (unchanged), an inner container with code, and the round trip above. npm test passes, including 100% coverage.

@github-actions github-actions Bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Oct 11, 2026
@wooorm wooorm closed this in f59183b Oct 30, 2026
@github-actions

This comment has been minimized.

@wooorm wooorm added the 💪 phase/solved Post is done label Oct 30, 2026
@github-actions github-actions Bot removed the 🤞 phase/open Post is being triaged manually label Oct 30, 2026
@wooorm

wooorm commented Oct 30, 2026

Copy link
Copy Markdown
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

Labels

💪 phase/solved Post is done

Development

Successfully merging this pull request may close these issues.

container directive do not work with fenced code blocks properly

2 participants