antfu / markdown-it-mdc

MDC (Markdown Components) syntax for markdown-it.
MIT License
106 stars 3 forks source link

Support attributes following a block element #1

Open luminarious opened 1 year ago

luminarious commented 1 year ago

Clear and concise description of the problem

Currently this plugin cannot handle when attributes are on a separate line. Example use case, where expected result is

antfu commented 1 year ago
image

It seems the behavior is a bit unpredictable/confusing to read. I am not very sure if we should support in. Even if we do, I think we'd need to update the MDC spec first before landing the implementation.

/cc @Atinux @farnabaz WDYT?

atinux commented 1 year ago

Does this work? If so, this is the clearest syntax IMO


::ul{.cool-list}
- List item
- List item
::
antfu commented 1 year ago

It will be compiled to this

<ul class="cool-list">
  <ul>
    <li>List item</li>
    <li>List item</li>
  </ul>
</ul>

I guess we might need a bit of special handling for it.

luminarious commented 1 year ago
image

It seems the behavior is a bit unpredictable/confusing to read. I am not very sure if we should support in. Even if we do, I think we'd need to update the MDC spec first before landing the implementation.

/cc @Atinux @farnabaz WDYT?

That's a valid concern. I would either: a) apply newline attributes based on indentation b) always apply newline attributes to closest block

Your new solution is neat and in line with general approach, but doesn't solve my use case where the plugin simply dies when trying to parse markdown that uses newline-attributes (for lack of a better term) 😅

Is there a way to make this plugin ignore newline-attributes so that markdown-it-attrs could handle parsing them?

antfu commented 1 year ago

You can disable it with: https://github.com/antfu/markdown-it-mdc/blob/5e34c911d279c04be192199d6cca1367dbd6cbc6/src/index.ts#L19C1-L25C26

Let me know if it doesn't work

luminarious commented 11 months ago

Disabling inline attributes did not help. Newline attributes in my source material continue to trip up the parsing :/