From b9d7793ff4c419fd6d8fd139eb6ae33b2f6c2e43 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 14 Nov 2020 12:56:20 +0300 Subject: fix: resolve eslint errors --- src/lib/Markdown/Section.tsx | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/lib/Markdown') diff --git a/src/lib/Markdown/Section.tsx b/src/lib/Markdown/Section.tsx index fc208b1..fb2933d 100644 --- a/src/lib/Markdown/Section.tsx +++ b/src/lib/Markdown/Section.tsx @@ -8,6 +8,10 @@ interface PropTypes extends ParserPropTypes { level?: number; } +interface MapperPropTypes extends PropTypes { + SectionComponent: React.FC; +} + const getHeaderLevel = (header: string): number => { if (!header) return 0; let level = 0; @@ -15,18 +19,21 @@ const getHeaderLevel = (header: string): number => { return level; }; -const ChildrenSections: React.FC = ({ rawLines, level = 0 }) => { - const childrenSectionLines = rawLines.reduce((sections: string[][], line: string) => { - if (line) { - if (getHeaderLevel(line) === level) sections.push([]); - if (sections.length) sections[sections.length - 1].push(line); - } - return sections; - }, []); - const children = childrenSectionLines.map(sectionLines =>
); +const SectionMapper: React.FC = ({ rawLines, level = 0, SectionComponent }) => { + const children = rawLines + .reduce((sections: string[][], line: string) => { + if (line) { + if (getHeaderLevel(line) === level) sections.push([]); + if (sections.length) sections[sections.length - 1].push(line); + } + return sections; + }, []) + .map(sectionLines => ); + return <>{children}; }; + const Section: React.FC = ({ rawLines, level = 0 }) => { const deeperLevelIndex = rawLines.findIndex(line => line.match(`^#{${level + 1},} .*$`)); const rawContent = rawLines.splice(0, (deeperLevelIndex < 0) ? rawLines.length : deeperLevelIndex); @@ -35,7 +42,7 @@ const Section: React.FC = ({ rawLines, level = 0 }) => { return ( <> - + ); } @@ -45,7 +52,7 @@ const Section: React.FC = ({ rawLines, level = 0 }) => { return ( - + ); }; -- cgit v1.2.3