From 09f8c6865fb9a7e239cc907e313db44cccb7b5e8 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 5 Apr 2020 21:57:13 +0300 Subject: feat: Paragraph -> Text, parse selfClosingHtml --- src/lib/Markdown/Content.tsx | 30 +++++++++++++++++++++++------- src/lib/Markdown/Paragraph.tsx | 12 ------------ src/lib/Markdown/Text.tsx | 10 ++++++++++ 3 files changed, 33 insertions(+), 19 deletions(-) delete mode 100644 src/lib/Markdown/Paragraph.tsx create mode 100644 src/lib/Markdown/Text.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(``); return line.match(regex) !== null; } +const denotesSelfClosingHtml = (line: string): any => { + const regex = /(<[^/\s]*[^<]*\/>)/g; + return line.match(regex); +} + const Content: React.FC = ({ rawLines }) => { if (!rawLines.length) return null; @@ -40,14 +45,25 @@ const Content: React.FC = ({ rawLines }) => { const dottedListLines = rawLines.splice(0, closeIndex).slice(0, closeIndex); dottedListLines.unshift(line); buffer =
    {dottedListLines.map(li =>
  • )}
; - } 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 =
; + } else if (denotesSelfClosingHtml(line) !== null) { + const match = denotesSelfClosingHtml(line)[0]; + const [before, after] = line.split(match); + console.log({ line, match, before, after}); + buffer = ( + <> + +
+ + + ); } else { - buffer = + buffer =

} return ( diff --git a/src/lib/Markdown/Paragraph.tsx b/src/lib/Markdown/Paragraph.tsx deleted file mode 100644 index f46199e..0000000 --- a/src/lib/Markdown/Paragraph.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; -import { InlineParserPropTypes } from './types'; -import InlineSyntax, { splitter } from './InlineSyntax'; - -const Paragraph: React.FC = ({ line }) => { - const result = line.split(splitter).map(span => ); - return

{result}

; -} - -export default Paragraph; - - diff --git a/src/lib/Markdown/Text.tsx b/src/lib/Markdown/Text.tsx new file mode 100644 index 0000000..b989476 --- /dev/null +++ b/src/lib/Markdown/Text.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import { InlineParserPropTypes } from './types'; +import InlineSyntax, { splitter } from './InlineSyntax'; + +const Text: React.FC = ({ line }) => { + return <>{line.split(splitter).map(span => )}; +} + +export default Text; + -- cgit v1.2.3