pablo-abc / svelte-markdown

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

default link behaviour target=blank #44

Closed pi43r closed 2 years ago

pi43r commented 2 years ago

Can I add this somewhere in the options? I couldn't find it at the marked documentation.

Or do I have to add it manually on:parsed?

pablo-abc commented 2 years ago

The way to do this would be to override the Link renderer. You can take the default one as a starting point and add your logic there. (E.g. check if the href as a protocol to see if its an external link or not. Add icons for external links. Etc.) When you have your renderer, you can pass it to <SvelteMarkdown> on its renderers prop like this:

<script>
  import Link from './CustomLink.svelte';

  export let source;

  const renderers = {
    link: Link,
  }
</script>

<SvelteMarkdown {source} {renderers} />

The parsed event is only to provide you a way to access to your the content after it's been parsed. For example, to add a table of contents.

I'm closing this, since it's not an issue per se! But feel free to ask more questions.

siawyoung commented 2 years ago

This helped me a lot, thank you so much!