From b78d78710c354a675aba9c280e9e9b066d4ea9e0 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Thu, 19 Mar 2020 23:12:22 +0300 Subject: [PATCH] Markdown component refactoring: move core to lib/text --- src/components/Markdown/index.tsx | 10 ++-------- src/lib/text.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 src/lib/text.ts diff --git a/src/components/Markdown/index.tsx b/src/components/Markdown/index.tsx index 2ede54d2..575e4b77 100644 --- a/src/components/Markdown/index.tsx +++ b/src/components/Markdown/index.tsx @@ -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 = memo(props => ( )) diff --git a/src/lib/text.ts b/src/lib/text.ts new file mode 100644 index 00000000..ebcf5956 --- /dev/null +++ b/src/lib/text.ts @@ -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) +}