diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-04-18 21:31:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-18 21:31:11 +0300 |
commit | dee39c8ff8e9a417ba2b338beb942f9ad443adf3 (patch) | |
tree | a6b1bfa00f5ad925d57d3ded655a8103b911fad4 /src/lib/Markdown/Section.tsx | |
parent | 62df0ff96fc9ab832212d223150862c7667d9ffc (diff) | |
parent | 0c061c74bfd473be17be755cd19c8952dc115a91 (diff) | |
download | react-benzin-dee39c8ff8e9a417ba2b338beb942f9ad443adf3.tar.gz |
Merge pull request #13 from eug-vs/develop
Patch 3.1.1
Diffstat (limited to 'src/lib/Markdown/Section.tsx')
-rw-r--r-- | src/lib/Markdown/Section.tsx | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/lib/Markdown/Section.tsx b/src/lib/Markdown/Section.tsx index 5ce8954..fc208b1 100644 --- a/src/lib/Markdown/Section.tsx +++ b/src/lib/Markdown/Section.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { Typography } from '@material-ui/core'; import ContentSection from '../ContentSection/ContentSection'; import Content from './Content'; import { ParserPropTypes } from './types'; @@ -10,9 +11,9 @@ interface PropTypes extends ParserPropTypes { const getHeaderLevel = (header: string): number => { if (!header) return 0; let level = 0; - while(header[level] === '#') level++; + while (header[level] === '#') level += 1; return level; -} +}; const ChildrenSections: React.FC<PropTypes> = ({ rawLines, level = 0 }) => { const childrenSectionLines = rawLines.reduce((sections: string[][], line: string) => { @@ -22,15 +23,22 @@ const ChildrenSections: React.FC<PropTypes> = ({ rawLines, level = 0 }) => { } return sections; }, []); - const children = childrenSectionLines.map(sectionLines => <Section rawLines={sectionLines} level={level}/>); - return <> {children} </>; -} + const children = childrenSectionLines.map(sectionLines => <Section rawLines={sectionLines} level={level} />); + return <>{children}</>; +}; const Section: React.FC<PropTypes> = ({ rawLines, level = 0 }) => { const deeperLevelIndex = rawLines.findIndex(line => line.match(`^#{${level + 1},} .*$`)); const rawContent = rawLines.splice(0, (deeperLevelIndex < 0) ? rawLines.length : deeperLevelIndex); - if (!level) return <ChildrenSections rawLines={rawLines} level={getHeaderLevel(rawLines[0])}/>; + if (!level) { + return ( + <> + <Typography><Content rawLines={rawContent} /></Typography> + <ChildrenSections rawLines={rawLines} level={getHeaderLevel(rawLines[0])} /> + </> + ); + } const sectionName = rawContent.splice(0, 1)[0].slice(level).trim(); const deeperLevel = getHeaderLevel(rawLines[0]); @@ -40,7 +48,7 @@ const Section: React.FC<PropTypes> = ({ rawLines, level = 0 }) => { <ChildrenSections rawLines={rawLines} level={deeperLevel} /> </ContentSection> ); -} +}; export default Section; |