From eda4a1dceeb3d8db5ce47a555f098dbaa1deb996 Mon Sep 17 00:00:00 2001 From: eug-vs 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') 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 = ({ rawLines }) => { @@ -19,6 +24,11 @@ const Content: React.FC = ({ rawLines }) => { const closeIndex = rawLines.findIndex(line => denotesCodeBlock(line)); const codeBlockLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex); result = + } else if (denotesDottedList(line)) { + const closeIndex = rawLines.findIndex(line => !denotesDottedList(line)); + const dottedListLines = rawLines.splice(0, closeIndex).slice(0, closeIndex); + dottedListLines.unshift(line); + result =
    {dottedListLines.map(li =>
  • )}
; } else { result = } @@ -28,7 +38,7 @@ const Content: React.FC = ({ rawLines }) => { { result } - ) + ); } export default Content; -- cgit v1.2.3