marked
marked copied to clipboard
highlight add parameters
Describe the feature A clear and concise description of what you would like. Add code parsing parameters
```html | preview <h1>111111</h1> ``` Why is this feature necessary? A clear and concise description of why.
I want to show code or render code
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
marked.setOptions({
renderer: new marked.Renderer(),
highlight(code, lang, params) {
console.log(params) // '| preview'
}
})
Markdown it support
highlight(str, lang, attrs) {
console.log(
'🚀 ~ file: vite.config.ts ~ line 20 ~ highlight ~ attrs',
attrs
)
}
The following code can be used instead
```ts | pre const a = 1; ```
marked.use({
renderer: {
code(code, infostring: string, escaped) {
const [lang, ...attrsString] = infostring.split(' | ')
console.log('lang', lang) // ts
console.log(attrsString) // [ 'pre' ]
const language = hljs.getLanguage(lang) ? lang : 'plaintext'
return `<pre><code class="hljs language-${lang}">${
hljs.highlight(code, { language }).value
}</code></pre>`
}
}
})
Syntax Highlighting is a part of Markdown Extended: https://www.markdownguide.org/extended-syntax/#syntax-highlighting