aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Markdown/Content.tsx
diff options
context:
space:
mode:
authorEug-VS <eug-vs@keemail.me>2020-04-04 22:05:40 +0300
committerEug-VS <eug-vs@keemail.me>2020-04-04 22:05:40 +0300
commitbdcc2edb38fb0e57604fa12d25b2a4b478261e18 (patch)
tree71aaedf7f4500cfcab9bd4f344b326dadd71d392 /src/lib/Markdown/Content.tsx
parent464b5fbef2f58cbcd134b7200c5f7c2f904202a0 (diff)
downloadreact-benzin-bdcc2edb38fb0e57604fa12d25b2a4b478261e18.tar.gz
refactor: structurize Markdown component :recycle:
Diffstat (limited to 'src/lib/Markdown/Content.tsx')
-rw-r--r--src/lib/Markdown/Content.tsx34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/Markdown/Content.tsx b/src/lib/Markdown/Content.tsx
new file mode 100644
index 0000000..b7829ed
--- /dev/null
+++ b/src/lib/Markdown/Content.tsx
@@ -0,0 +1,34 @@
+import React from 'react';
+
+import CodeBlock from './CodeBlock';
+import { ParserPropTypes } from './types';
+
+
+const denotesCodeBlock = (line: string): boolean => {
+ return line.slice(0, 3) === '```';
+}
+
+const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
+ if (!rawLines.length) return null;
+
+ const line = rawLines.splice(0, 1)[0];
+
+ let result;
+ if (denotesCodeBlock(line)) {
+ const closeIndex = rawLines.findIndex(line => denotesCodeBlock(line));
+ const codeBlockLines = rawLines.splice(0, closeIndex);
+ result = <CodeBlock rawLines={codeBlockLines} />
+ } else {
+ result = <p> {line} </p>
+ }
+
+ return (
+ <>
+ { result }
+ <Content rawLines={rawLines} />
+ </>
+ )
+}
+
+export default Content;
+