Closed manniL closed 2 years ago
/cc @meteorlxy 👀
Well... I'd say this is kind of as expected, because we are treating vue components as html block tags, instead of inline tags. That's say this plugin is stricter than vite-plugin-md.
See the differences between inline tags and block tags:
Maybe we could expose an API to allow users customizing which components should be treated as inline 🤔 ?
This option should help with your case:
componentOptions: {
inlineTags: ['mdi-github'],
}
Well... I'd say this is kind of as expected, because we are treating vue components as html block tags, instead of inline tags. That's say this plugin is stricter than vite-plugin-md.
Interesting insight, thanks! Could you briefly highlight why Vue components are treated as block tags and not as inline tags "anymore" (compared to vite-plugin-md
)?
This option should help with your case:
componentOptions: { inlineTags: ['mdi-github'], }
Thanks for providing a quick workaround for that issue 👍🏻
Do you think it'd be reasonable to have a flag that automatically treats all components as inline tags? So compat with vite-plugin-md
is better (e.g. some of my slides are broken because of the switch in Slidev itself so a flag which could be set in Slidev might mitigate this issue)
@manniL
The behavior of block tags would be better in a more common case - write component in multi-line:
<Foo
class="foobar"
title="baz"
/>
Check the differences here.
You'll notice that the inline one is wrapped with a <p>
tag, which might not be expected for Vue components.
In fact, they are almost the same in most cases. What you reported is one of the edge cases that the behaviors differ. If the tag is not at the beginning of the list item, everything will work as expected:
* <div/> [Example link](https://github.com/)
* foobar<div/> [Example link](https://github.com/)
The reason is that a html block at the beginning of a line somehow "terminates" the parsing of the entire line.
It looks weird indeed, but markdown-it says it is a 100%-done-right CommonMark parser, so :expressionless:
Thanks for the detailed answer!
Would it make sense to differ between multi-line Vue components (block-level by default) and "inline" Vue components (inline-level by default) then? Sadly I'm not aware of the internals and if that's possible but this would kill two birds with one stone: No superfluous (or possibly even bug-introducing) <p>
tag around multi-line components and compat behavior (for most cases).
There could be a solution for that, but in fact I'm also not an expert of the markdown-it parsing flow so I didn't solve it yet 😢 .
@manniL Good news, I think I made it at least for this case 😃
I think the behavior is acceptable and only slightly violates the CommonMark spec.
Component tags would behave differently from block & inline tags:
Terminate the line:
<!-- input -->
<div /> [link](link)
<!-- output -->
<div /> [link](link)
As normal inline content being wrapped with <p>
:
<!-- input -->
<span /> [link](link)
<!-- output -->
<p><span /> <a href="link">link</a></p>
Won't terminate the line and won't be wrapped with <p>
:
<!-- input -->
<Counter /> [link](link)
<!-- output -->
<Counter /> <a href="link">link</a>
That looks pretty good 👍🏻 I also like the distinct differentiation between inline, block and component tags.
Describe the bug
When using a Vue component followed by a markdown link in a list item, the link is not rendered correctly. This worked with https://github.com/antfu/vite-plugin-md (Slidev v0.33.0 and before) For example:
* <Counter /> [Example link](https://github.com/)
.Related: https://github.com/slidevjs/slidev/issues/658
Manual reproduction:
* <Counter /> [Test Link](https://github.com/)
as last line inindex.md
in the examples folder.Reproduction
https://stackblitz.com/edit/slidev-nxyjmy?file=slides.md
System Info
Used Package Manager
yarn
Validations