diff options
author | eug-vs <eug-vs@keemail.me> | 2020-04-05 20:02:05 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-04-05 20:02:05 +0300 |
commit | eda4a1dceeb3d8db5ce47a555f098dbaa1deb996 (patch) | |
tree | ef45604048ec79e622ded663df4494fdb59a4852 /src/lib/Markdown | |
parent | b26b6c045419893bc375616d8f186bd41c5ccca1 (diff) | |
download | react-benzin-eda4a1dceeb3d8db5ce47a555f098dbaa1deb996.tar.gz |
feat: parse dotted lists
Diffstat (limited to 'src/lib/Markdown')
-rw-r--r-- | src/lib/Markdown/Content.tsx | 14 |
1 files changed, 12 insertions, 2 deletions
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; |