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


From a35cdfebf2d8c53c77900fee0826d4a967290e5d Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 5 Apr 2020 01:01:30 +0300
Subject: feat: add Paragraph component

---
 src/lib/Markdown/Content.tsx | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

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

diff --git a/src/lib/Markdown/Content.tsx b/src/lib/Markdown/Content.tsx
index b7829ed..2a9e2ee 100644
--- a/src/lib/Markdown/Content.tsx
+++ b/src/lib/Markdown/Content.tsx
@@ -1,6 +1,7 @@
 import React from 'react';
 
 import CodeBlock from './CodeBlock';
+import Paragraph from './Paragraph';
 import { ParserPropTypes } from './types';
 
 
@@ -16,10 +17,10 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
   let result;
   if (denotesCodeBlock(line)) {
     const closeIndex = rawLines.findIndex(line => denotesCodeBlock(line));
-    const codeBlockLines = rawLines.splice(0, closeIndex);
+    const codeBlockLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex);
     result = <CodeBlock rawLines={codeBlockLines} />
   } else {
-    result = <p> {line} </p>
+    result = <Paragraph data={line} />
   }
 
   return (
-- 
cgit v1.2.3


From 39e1d32c669545ccc30e0d424323c6a01317c4be Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 5 Apr 2020 12:56:41 +0300
Subject: refactor: move some logic to InlineSyntax.tsx

---
 src/lib/Markdown/Content.tsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

diff --git a/src/lib/Markdown/Content.tsx b/src/lib/Markdown/Content.tsx
index 2a9e2ee..d0a2193 100644
--- a/src/lib/Markdown/Content.tsx
+++ b/src/lib/Markdown/Content.tsx
@@ -20,7 +20,7 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
     const codeBlockLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex);
     result = <CodeBlock rawLines={codeBlockLines} />
   } else {
-    result = <Paragraph data={line} />
+    result = <Paragraph line={line} />
   }
 
   return (
-- 
cgit v1.2.3


From eda4a1dceeb3d8db5ce47a555f098dbaa1deb996 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 5 Apr 2020 20:02:05 +0300
Subject: feat: parse dotted lists

---
 src/lib/Markdown/Content.tsx | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

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

diff --git a/src/lib/Markdown/Content.tsx b/src/lib/Markdown/Content.tsx
index d0a2193..593b9e9 100644
--- a/src/lib/Markdown/Content.tsx
+++ b/src/lib/Markdown/Content.tsx
@@ -2,11 +2,16 @@ import React from 'react';
 
 import CodeBlock from './CodeBlock';
 import Paragraph from './Paragraph';
+import InlineSyntax from './InlineSyntax';
 import { ParserPropTypes } from './types';
 
 
 const denotesCodeBlock = (line: string): boolean => {
-  return line.slice(0, 3) === '```';
+  return line.match(/^```.*$/) !== null;
+}
+
+const denotesDottedList = (line: string): boolean => {
+  return line.match(/^ ?- .*$/) !== null;
 }
 
 const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
@@ -19,6 +24,11 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
     const closeIndex = rawLines.findIndex(line => denotesCodeBlock(line));
     const codeBlockLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex);
     result = <CodeBlock rawLines={codeBlockLines} />
+  } else if (denotesDottedList(line)) {
+    const closeIndex = rawLines.findIndex(line => !denotesDottedList(line));
+    const dottedListLines = rawLines.splice(0, closeIndex).slice(0, closeIndex);
+    dottedListLines.unshift(line);
+    result = <ul>{dottedListLines.map(li => <li><InlineSyntax line={li} /></li>)}</ul>;
   } else {
     result = <Paragraph line={line} />
   }
@@ -28,7 +38,7 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
       { result }
       <Content rawLines={rawLines} />
     </>
-  )
+  );
 }
 
 export default Content;
-- 
cgit v1.2.3


From b6e58c0f8eebb0447e5330b983ec387dbf2a59c0 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 5 Apr 2020 20:42:25 +0300
Subject: feat: parse html :rocket:

---
 src/lib/Markdown/Content.tsx | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

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

diff --git a/src/lib/Markdown/Content.tsx b/src/lib/Markdown/Content.tsx
index 593b9e9..1f0fcfc 100644
--- a/src/lib/Markdown/Content.tsx
+++ b/src/lib/Markdown/Content.tsx
@@ -14,28 +14,45 @@ const denotesDottedList = (line: string): boolean => {
   return line.match(/^ ?- .*$/) !== null;
 }
 
+const denotesOpenHtmlTag = (line: string): string => {
+  const regex = /<([^/\s]*)[^<]*[^/]>/g;
+  const match = regex.exec(line);
+  return match ? match[1] : '';
+}
+
+const denotesClosingHtmlTag = (line: string, tag: string): boolean => {
+  const regex = new RegExp(`</${tag}[^<]*>`);
+  return line.match(regex) !== null;
+}
+
 const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
   if (!rawLines.length) return null;
 
   const line = rawLines.splice(0, 1)[0];
 
-  let result;
+  let buffer;
   if (denotesCodeBlock(line)) {
     const closeIndex = rawLines.findIndex(line => denotesCodeBlock(line));
     const codeBlockLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex);
-    result = <CodeBlock rawLines={codeBlockLines} />
+    buffer = <CodeBlock rawLines={codeBlockLines} />
   } else if (denotesDottedList(line)) {
     const closeIndex = rawLines.findIndex(line => !denotesDottedList(line));
     const dottedListLines = rawLines.splice(0, closeIndex).slice(0, closeIndex);
     dottedListLines.unshift(line);
-    result = <ul>{dottedListLines.map(li => <li><InlineSyntax line={li} /></li>)}</ul>;
+    buffer = <ul>{dottedListLines.map(li => <li><InlineSyntax line={li} /></li>)}</ul>;
+  } else if (denotesOpenHtmlTag(line)) {
+    const tag = denotesOpenHtmlTag(line);
+    const closeIndex = rawLines.findIndex(line => denotesClosingHtmlTag(line, tag));
+    const htmlLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex);
+    htmlLines.unshift(line);
+    buffer = <div dangerouslySetInnerHTML={{ __html: htmlLines.join('\n') }}></div>;
   } else {
-    result = <Paragraph line={line} />
+    buffer = <Paragraph line={line} />
   }
 
   return (
     <>
-      { result }
+      { buffer }
       <Content rawLines={rawLines} />
     </>
   );
-- 
cgit v1.2.3


From 09f8c6865fb9a7e239cc907e313db44cccb7b5e8 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 5 Apr 2020 21:57:13 +0300
Subject: feat: Paragraph -> Text, parse selfClosingHtml

---
 src/lib/Markdown/Content.tsx | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

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

diff --git a/src/lib/Markdown/Content.tsx b/src/lib/Markdown/Content.tsx
index 1f0fcfc..e27b63f 100644
--- a/src/lib/Markdown/Content.tsx
+++ b/src/lib/Markdown/Content.tsx
@@ -1,7 +1,7 @@
 import React from 'react';
 
 import CodeBlock from './CodeBlock';
-import Paragraph from './Paragraph';
+import Text from './Text';
 import InlineSyntax from './InlineSyntax';
 import { ParserPropTypes } from './types';
 
@@ -14,17 +14,22 @@ const denotesDottedList = (line: string): boolean => {
   return line.match(/^ ?- .*$/) !== null;
 }
 
-const denotesOpenHtmlTag = (line: string): string => {
+const denotesOpenHtml= (line: string): string => {
   const regex = /<([^/\s]*)[^<]*[^/]>/g;
   const match = regex.exec(line);
   return match ? match[1] : '';
 }
 
-const denotesClosingHtmlTag = (line: string, tag: string): boolean => {
+const denotesClosingHtml= (line: string, tag: string): boolean => {
   const regex = new RegExp(`</${tag}[^<]*>`);
   return line.match(regex) !== null;
 }
 
+const denotesSelfClosingHtml = (line: string): any => {
+  const regex = /(<[^/\s]*[^<]*\/>)/g;
+  return line.match(regex);
+}
+
 const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
   if (!rawLines.length) return null;
 
@@ -40,14 +45,25 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
     const dottedListLines = rawLines.splice(0, closeIndex).slice(0, closeIndex);
     dottedListLines.unshift(line);
     buffer = <ul>{dottedListLines.map(li => <li><InlineSyntax line={li} /></li>)}</ul>;
-  } else if (denotesOpenHtmlTag(line)) {
-    const tag = denotesOpenHtmlTag(line);
-    const closeIndex = rawLines.findIndex(line => denotesClosingHtmlTag(line, tag));
+  } else if (denotesOpenHtml(line)) {
+    const tag = denotesOpenHtml(line);
+    const closeIndex = rawLines.findIndex(line => denotesClosingHtml(line, tag));
     const htmlLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex);
     htmlLines.unshift(line);
     buffer = <div dangerouslySetInnerHTML={{ __html: htmlLines.join('\n') }}></div>;
+  } else if (denotesSelfClosingHtml(line) !== null) {
+    const match = denotesSelfClosingHtml(line)[0];
+    const [before, after] = line.split(match);
+    console.log({ line, match, before, after});
+    buffer = (
+      <>
+        <Text line={before} />
+        <div dangerouslySetInnerHTML={{ __html: match }}></div>
+        <Text line={after} />
+      </>
+    );
   } else {
-    buffer = <Paragraph line={line} />
+    buffer = <p><Text line={line} /></p>
   }
 
   return (
-- 
cgit v1.2.3


From 828946eb02bdfaa7ec5631f1e854881f874f7b7e Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 5 Apr 2020 22:06:54 +0300
Subject: refactor: rename InlineSyntax -> SyntacticSpan

---
 src/lib/Markdown/Content.tsx | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

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

diff --git a/src/lib/Markdown/Content.tsx b/src/lib/Markdown/Content.tsx
index e27b63f..caac91c 100644
--- a/src/lib/Markdown/Content.tsx
+++ b/src/lib/Markdown/Content.tsx
@@ -2,7 +2,6 @@ import React from 'react';
 
 import CodeBlock from './CodeBlock';
 import Text from './Text';
-import InlineSyntax from './InlineSyntax';
 import { ParserPropTypes } from './types';
 
 
@@ -44,7 +43,7 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
     const closeIndex = rawLines.findIndex(line => !denotesDottedList(line));
     const dottedListLines = rawLines.splice(0, closeIndex).slice(0, closeIndex);
     dottedListLines.unshift(line);
-    buffer = <ul>{dottedListLines.map(li => <li><InlineSyntax line={li} /></li>)}</ul>;
+    buffer = <ul>{dottedListLines.map(li => <li><Text line={li.slice(2)} /></li>)}</ul>;
   } else if (denotesOpenHtml(line)) {
     const tag = denotesOpenHtml(line);
     const closeIndex = rawLines.findIndex(line => denotesClosingHtml(line, tag));
-- 
cgit v1.2.3


From 43d65a56bbe91de967fa2ff86b25ec216bfd5ce1 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 5 Apr 2020 22:16:02 +0300
Subject: style: fix linting errors :rotating_light:

---
 src/lib/Markdown/Content.tsx | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

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

diff --git a/src/lib/Markdown/Content.tsx b/src/lib/Markdown/Content.tsx
index caac91c..aaea100 100644
--- a/src/lib/Markdown/Content.tsx
+++ b/src/lib/Markdown/Content.tsx
@@ -24,7 +24,7 @@ const denotesClosingHtml= (line: string, tag: string): boolean => {
   return line.match(regex) !== null;
 }
 
-const denotesSelfClosingHtml = (line: string): any => {
+const denotesSelfClosingHtml = (line: string): string[] | null => {
   const regex = /(<[^/\s]*[^<]*\/>)/g;
   return line.match(regex);
 }
@@ -44,14 +44,14 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
     const dottedListLines = rawLines.splice(0, closeIndex).slice(0, closeIndex);
     dottedListLines.unshift(line);
     buffer = <ul>{dottedListLines.map(li => <li><Text line={li.slice(2)} /></li>)}</ul>;
-  } else if (denotesOpenHtml(line)) {
-    const tag = denotesOpenHtml(line);
+  } else if ((buffer = denotesOpenHtml(line))) {
+    const tag = buffer;
     const closeIndex = rawLines.findIndex(line => denotesClosingHtml(line, tag));
     const htmlLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex);
     htmlLines.unshift(line);
     buffer = <div dangerouslySetInnerHTML={{ __html: htmlLines.join('\n') }}></div>;
-  } else if (denotesSelfClosingHtml(line) !== null) {
-    const match = denotesSelfClosingHtml(line)[0];
+  } else if ((buffer = denotesSelfClosingHtml(line)) !== null) {
+    const match = buffer[0];
     const [before, after] = line.split(match);
     console.log({ line, match, before, after});
     buffer = (
-- 
cgit v1.2.3

