Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested directive container not working properly #11

Closed
4 tasks done
lab9fr opened this issue Jan 2, 2025 · 7 comments
Closed
4 tasks done

nested directive container not working properly #11

lab9fr opened this issue Jan 2, 2025 · 7 comments
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@lab9fr
Copy link

lab9fr commented Jan 2, 2025

Initial checklist

Affected package

mdast-util-directive

Steps to reproduce

parsing this markdown :

:::outside

:::inside
Hello
:::

:::inside
World
:::

:::

Actual behavior

the first closing pattern ::: closes the inside and outside containers instead of just the last one opened

So they are nested, but only one container can be nested in an another one, the "World" container isn't in the outside container as expected

Expected behavior

the closing pattern should only close one container, not several at a time and only the deepest (latest) one opened.

Runtime

No response

Package manager

No response

Operating system

No response

Build and bundle tools

No response

@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 Jan 2, 2025
@wooorm
Copy link
Member

wooorm commented Jan 2, 2025

Why? Your proposal breaks some use cases. Why is it better than those use cases?

@lab9fr
Copy link
Author

lab9fr commented Jan 3, 2025

Hello @wooorm,

Thanks for the quick response.
I'm curious about the use cases it would break.

For us, it makes the container directive difficult to use, because you can't put one inside an another and expect them to act as html containers, one closing tag for one opening tag and several siblings existing inside a container.

For example, we'd like to use the container to create a tabs component :

:::tabs

:::tab[tab1]
Hello
:::

:::tab[tab2]
World
:::

:::

We have a workaround for this specific case, but it seems to me this is closer to the way html works.

May be it would be an another type of directive, like a 4th level ?

Thanks

@ChristianMurphy
Copy link
Member

Also see the discussion in micromark/micromark-extension-directive#8

@wooorm
Copy link
Member

wooorm commented Jan 3, 2025

Sure you can put them inside each other:

::::tabs

:::tab[tab1]
Hello
:::

:::tab[tab2]
World
:::

::::

https://github.com/micromark/micromark-extension-directive#syntax

Fenced code works the same. You can nest several things in markdown by using more markers around less markers

@wooorm wooorm closed this as completed Jan 3, 2025
@wooorm wooorm added the 🙋 no/question This does not need any changes label Jan 3, 2025

This comment has been minimized.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Jan 3, 2025
@lab9fr
Copy link
Author

lab9fr commented Jan 3, 2025

Thank you for your responses and the link to the discussion. It helped clarify the matter.

I do see one drawback with this hierarchical nesting approach: the container needs to be aware of its contents to determine the appropriate level.

Taking the tab example again, if each tab's content is externalized into separate markdown files (which is something we’re planning to do), it might become challenging to identify the correct level to use.

Thanks.

@wooorm
Copy link
Member

wooorm commented Jan 3, 2025

Yep. That’s indeed one of the aspects of this. But you will see it in many languages, such as Rust strings too. Markdown is often very context dependent.

Though, your argumentation about externalizing into separate files is of no consequence.
To do that, you will work with ASTs. For that we provide the tools. Those tools automatically do what you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

3 participants