From 464b5fbef2f58cbcd134b7200c5f7c2f904202a0 Mon Sep 17 00:00:00 2001 From: Eug-VS Date: Sat, 4 Apr 2020 20:43:00 +0300 Subject: feat: parse CodeBlocks --- src/lib/Markdown/Markdown.tsx | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/lib/Markdown/Markdown.tsx') diff --git a/src/lib/Markdown/Markdown.tsx b/src/lib/Markdown/Markdown.tsx index 332d08c..8d93437 100644 --- a/src/lib/Markdown/Markdown.tsx +++ b/src/lib/Markdown/Markdown.tsx @@ -18,9 +18,35 @@ const header = (level: number): string => { return `^#{${level}} .*$`; } +const CodeBlock: React.FC<{ rawLines: String[]}> = ({ rawLines }) => { + return ( +

+ {rawLines.map(line => <> {line}
)} +

+ ); +} + + const Content: React.FC = ({ rawLines }) => { - const plainText = rawLines.map(line =>

{line}

); - return

{plainText}

; + if (!rawLines.length) return <>; + const line = rawLines[0]; + const otherLines = rawLines.slice(1); + if (line.slice(0, 3) === '```') { + const closeIndex = otherLines.findIndex(line => line.slice(0, 3) === '```'); + console.log({ line, otherLines, closeIndex }); + return ( + <> + + + + ) + } + return ( + <> +

{line}

+ + + ) } const Level: React.FC = ({ rawLines, level = 0 }) => { -- cgit v1.2.3