Skip to content

Conversation

@brunobeltran
Copy link

An alternative proposal to #36 (fixes #13, thanks @nthiery for your pass at this, which inspired me to give it a shot).

Avoids the need for an explicit list of "container_names" (which doesn't seem like an appropriate thing for mdformat_myst to manage) by instead recursively calling mdformat's API directly. I'm not sure if there are any negative consequences to this, as I'm not very knowledgable on the mdformat codebase, but it doesn't seem to lead to a performance regression on $DAY_JOB's monorepo, at least.

Note that this PR also proposes a very noticeably different set of semantics for when to add padding newlines, namely: I only add padding newlines around child colon fences, so "regular" (e.g. paragraph) content does not get additional padding, maintaining more similarity with the current behavior.

@brunobeltran brunobeltran force-pushed the bruno/colon-fence-for-upstream branch from df6eb7b to 4b3ff3a Compare January 4, 2026 02:40
@brunobeltran
Copy link
Author

@KyleKing are you still the right person to review this? Sorry for the inbox-blast if not (and please let me know if there's a better comms channel than just GitHub comments for this)!

@nthiery
Copy link

nthiery commented Jan 4, 2026

Great; thank you @brunobeltran for taking over ;-)

Copy link
Collaborator

@KyleKing KyleKing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments and overall looks like this should work with some caveats on performance. Thanks!

:::{tip} Nested tip in list item
Tip content inside a list item.
:::
.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not already added, can you make sure that other edge cases are tested? For example: with an empty directive, with arguments, containing a code block and deeper nesting, and maybe one to test that regular content with ::: is handled

Additionally, are any tests from #36 not covered here?

return text


CHANGES_AST = True
Copy link
Collaborator

@KyleKing KyleKing Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this strictly necessary? Turning this on can introduce a lot of risk -- I'm assuming this is required to deal with the recursion?

plugin = mdformat.plugins.PARSER_EXTENSIONS[plugin_name]
if plugin not in mdit.options["parser_extension"]:
mdit.options["parser_extension"].append(plugin)
plugin.update_mdit(mdit)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 🌟

Comment on lines +126 to +128
formatted += mdformat.text(
content, options=context.options, extensions=extension_names
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little worried about this the performance here and would prefer to have native support like regex parsing (proposed in #36), but directive content should be small and is something we could revisit

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bigger issue is that I don't think any other plugin uses mdformat recursively like this, so it could lead to unexpected behavior

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.

colon fence syntax is broken by escape character

3 participants