pablo-abc / svelte-markdown

Markdown parser to svelte components
MIT License
360 stars 50 forks source link

Feature request: Custom components #8

Open asv7c2 opened 3 years ago

asv7c2 commented 3 years ago

I think it be nice to have support for custom components in markdown.

pablo-abc commented 3 years ago

Hi! If by custom components you mean customising which components svelte-markdown uses to render the markdown, then that's already a core feature of this package!. I'm currently using exactly this for Felte's documentation site, you may check how I'm using it in the source code.

If you mean custom components as in web components, then I feel that should be a different package since that wouldn't need to be specifically tied to Svelte.

asv7c2 commented 3 years ago

@pablo-abc hi. I mean svelte components, not web components. Besides renderers add components property.

<script>
import Counter from ...
import SvelteMarkdown from 'svelte-markdown';

const source = '<Counter />';
</script>

<SvelteMarkdown components={{ Counter }} {source} />
pablo-abc commented 3 years ago

Ah, I think I understand what you mean. So, this is not in this scope of this package, since it would involve actually compiling the markdown as a Svelte file. If you want this behaviour, you probably want mdsvex which would allow you to use markdown as Svelte components.

asv7c2 commented 3 years ago

@pablo-abc

Sadly, mdsvex won't allow parse markdown at runtime. That's why i choose your package. By the way, i can try implement svelte component support and send you pull request.

pablo-abc commented 3 years ago

I personally don't see the value of compiling Svelte code at runtime for this package. It would considerably increase the complexity and bundle size of this package; and we would be repeating what mdsvex already does. I understand mdsvex does allow you to compile at runtime, I guess you'd need to pass the result of that to the Svelte compiler.

For now, if this is to be used I guess you'd need to tap into Marked's tokeniser to recognise Svelte components but it's in my future plans to migrate this to use Remark instead of Marked to make use of their ecosystem. In this sense maybe something like this could be a remark plugin.

Anyway development for this is quite slow right now since I'm focusing on Felte so I can't make any promises on when this migration would take place.