pablo-abc / svelte-markdown

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

How to render token type code not as codespan? #68

Closed yozawiratama closed 1 year ago

yozawiratama commented 1 year ago

I trying to render code like this

<script>
  import SvelteMarkdown from 'svelte-markdown'
  import { marked } from 'marked'

  const tokens = marked.lexer('```sql \n' +
      'select * from tbl \n' +
      '```')

  marked.walkTokens(tokens, token=> {
      console.log(token)
  })
</script>

<SvelteMarkdown source={tokens} />

but when I check in console, it still recognized as codespan

{
    "type": "codespan",
    "raw": "```SQL \nSELECT * FROM TBL \n```",
    "text": "sql  select * from tbl  "
}

how to render it as code?

yozawiratama commented 1 year ago

I already found it, we can't render it from string like that, but we can use textarea to test it, this is example code

<script>
    import SvelteMarkdown from 'svelte-markdown'
    // import {marked} from 'marked'
    var md = '**hello world**';

</script>

<textarea bind:value={md}></textarea>

<SvelteMarkdown source={md}
                />