micromark / micromark-extension-directive

micromark extension to support generic directives (`:cite[smith04]`)
https://unifiedjs.com
MIT License
29 stars 16 forks source link

Custom container parser #11

Closed podlomar closed 3 years ago

podlomar commented 3 years ago

Initial checklist

Problem

I would like to have a container with non-markdown content, e.g. YAML. Something like:

:::config
this: is
some: yaml
:::

The parser tries to parse this into markdown.

Solution

I would like to be able to specify a function which would be called on every directive and give me a chance to parse the content myself or leave it to the default parser.

I would contribute the solution myself, but I am not yet familiar with the internals of the parser. Also I am not sure if this feature aligns with the intensions of this extension.

Alternatives

I suppose I could take the position in the resulting AST to extract the raw content of the container. However, this feels like a hack.

wooorm commented 3 years ago

Hi there!

The goal of directives is that they parse in one single way, even if the “component” is unknown. This would theoretically allow for example GitHub to parse directives, and display them a certain way, even though it does not know which semantics you imply to them.

I would recommend using indented/fenced code inside the directive (container), and parsing that when you handle config directives.

See also: https://github.com/remarkjs/remark-directive/issues/1 (a similar discussion, and I especially think the alternative there would work for you).

github-actions[bot] commented 3 years ago

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.

podlomar commented 3 years ago

Ok, thank you for the clarification. I see the point. The proposed solutions isn't IMHO the nicest, but I can certainly live with it