enpitsuLin / solidjs-markdown

Markdown component for SolidJS
MIT License
2 stars 0 forks source link

Is there an option to target='_blank' for hyperlinks? #2

Open devUserContact opened 3 months ago

devUserContact commented 3 months ago

My markdown is rendering well. However, I checked the provided example and I was not able to find anything beyond simply rendering the markdown 'as is'.

Thanks in advance, best

enpitsuLin commented 3 months ago

you can use https://github.com/rehypejs/rehype-external-links and set option target to set target attr for external link.

like this (should work but I haven't try)

import rehypeExternalLinks from 'rehype-external-links'
import SolidjsMarkdown from 'solidjs-markdown'
import { render } from 'solid-js/web'

render(
  () => (
    <SolidjsMarkdown
      rehypePlugins={[
        [rehypeExternalLinks, { target: "_blank" }]
      ]}
    >
      # Hello, * world * !
    </SolidjsMarkdown>
  ),
  document.querySelector('#app')
)

maybe add more example later