antfu/markdown-it-mdc

Support attributes following a block element

Opened this issue · 6 comments

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

    * List item
    * List item
    {.cool-list}
    

    Suggested solution

    Plugin markdown-it-attrs supports this syntax, so currently markdown-it-mdc simply errors when encountering this syntax. At a minimum should probably mention in the readme that these two plugins are incompatible.

    Alternative

    No response

    Additional context

    No response

    Validations

antfu commented
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

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

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

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.

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?

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