From bdcc2edb38fb0e57604fa12d25b2a4b478261e18 Mon Sep 17 00:00:00 2001
From: Eug-VS <eug-vs@keemail.me>
Date: Sat, 4 Apr 2020 22:05:40 +0300
Subject: refactor: structurize Markdown component :recycle:

---
 src/lib/Markdown/Content.tsx | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 src/lib/Markdown/Content.tsx

(limited to 'src/lib/Markdown/Content.tsx')

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;
+
-- 
cgit v1.2.3

