Files
remanso/src/hooks/useMarkdown.hook.ts
2021-05-09 10:45:47 +02:00

31 lines
762 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import MarkdownIt from 'markdown-it'
import markdownItClass from '@toycode/markdown-it-class'
import blockEmbedPlugin from 'markdown-it-block-embed'
const md = new MarkdownIt({
typographer: true,
quotes: ['«\xA0', '\xA0»', '\xA0', '\xA0']
})
.use(markdownItClass, {
h1: ['title', 'is-2'],
h2: ['title', 'is-3'],
h3: ['title', 'is-4'],
h4: ['title', 'is-5'],
h5: ['title', 'is-6'],
h6: ['title', 'is-6'],
table: ['table', 'is-fullwidth']
})
.use(blockEmbedPlugin, {
youtube: {
width: '100%'
}
})
export const useMarkdown = () => {
return {
renderString: (content: string) => md.render(content),
render: (content: string) =>
md.render(decodeURIComponent(escape(atob(content))))
}
}