npm install --save-dev @types/showdown showdown
default export
が
import showdown from 'showdown'
showdown.extension('myext', [拡張])
?[alt](href)
を
なregex
に
showdown.extension('video', {
type: 'lang',
regex: /\n\?\[(.*)\]\((.*)\)\n/.source,
replace: `<p><video src="$2" controls>$1</video></p>`
})
showdown.extension('hljs', {
type: 'lang',
regex: /`{3}.+\n[^]+?\n`{3}/.source,
replace: (code: string) => {
const re = /^`{3}(.+)\n([^]+)\n`{3}$/
const match = re.exec(code)
if (! match || match.length < 3)
throw new Error('FAILED TO HIGHLIGHT CODE FENCE')
const [, lang, raw] = match
const { value } = hljs.highlight(lang, raw)
return `<pre class="hljs"><code>${value}</code></pre>`
}
})
import { Converter } from 'showdown'
const converter = new Converter({
extensions: ['video', 'hljs'],
simpleLineBreaks: true
})
const html = converter.makeHtml(markdown)
simpleLineBreaks
は<br>
に