Markdown component refactoring: move core to lib/text
This commit is contained in:
1 parent
bb393becc4
commit
b78d78710c
2 files changed
+21
-8
No files matched your search
@@ -1,12 +1,6 @@
|
||||
import { Html } from 'src/components/Html'
|
||||
import MarkdownIt from 'markdown-it'
|
||||
import Typograf from 'typograf'
|
||||
import { memo } from 'react'
|
||||
|
||||
const tp = new Typograf({ locale: ['ru'] })
|
||||
const md = new MarkdownIt({
|
||||
html: true,
|
||||
})
|
||||
import { typograf, markdownToHtml } from 'src/lib/text'
|
||||
|
||||
export type MarkdownProps = {
|
||||
data: string
|
||||
@@ -14,6 +8,6 @@ export type MarkdownProps = {
|
||||
|
||||
export const Markdown: React.SFC<MarkdownProps> = memo(props => (
|
||||
<Html
|
||||
html={tp.execute(md.render(props.data))}
|
||||
html={typograf(markdownToHtml(props.data))}
|
||||
/>
|
||||
))
|
||||
@@ -0,0 +1,19 @@
|
||||
import MarkdownIt from 'markdown-it'
|
||||
import Typograf from 'typograf'
|
||||
|
||||
const tp = new Typograf({ locale: ['ru'] })
|
||||
const md = new MarkdownIt({
|
||||
html: true,
|
||||
})
|
||||
|
||||
export type MarkdownProps = {
|
||||
data: string
|
||||
}
|
||||
|
||||
export function markdownToHtml(data: string): string {
|
||||
return md.render(data)
|
||||
}
|
||||
|
||||
export function typograf(data: string): string {
|
||||
return tp.execute(data)
|
||||
}
|
||||
Reference in new issue
Block a user