From 59ad386ba86845011fb7d236cbd6a2b96cb9a1e1 Mon Sep 17 00:00:00 2001 From: ae_atrofimov Date: Wed, 2 Oct 2024 13:20:28 +0200 Subject: [PATCH] feat(docs): added list handle --- .../ParserOpenRPC/DetailsBox/MDContent.tsx | 61 ++++++++++--------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/components/ParserOpenRPC/DetailsBox/MDContent.tsx b/src/components/ParserOpenRPC/DetailsBox/MDContent.tsx index 40bce9fe665..1cc4bc463ea 100644 --- a/src/components/ParserOpenRPC/DetailsBox/MDContent.tsx +++ b/src/components/ParserOpenRPC/DetailsBox/MDContent.tsx @@ -1,43 +1,48 @@ import React from "react"; -const parseLists = (content: string) => { - const lines = content.split('\n'); +const parseLists = (text: string) => { + const lines = text.split('\n'); let result = ''; - let isFirstLevelOpen = false; - let isSecondLevelOpen = false; + let inList = false; + let inSubList = false; + lines.forEach((line) => { - if (line.match(/^ {2}-\s+/)) { - if (!isSecondLevelOpen) { - result += ''; - isSecondLevelOpen = false; + const trimmed = line.trim(); + const isListItem = trimmed.startsWith('- '); + const isSubListItem = line.startsWith(' - '); + + if (isListItem && !isSubListItem) { + if (!inList) { + result += '\n'; + inSubList = false; } - if (!isFirstLevelOpen) { - result += '\n'; + inSubList = false; } - if (isFirstLevelOpen) { - result += ''; - isFirstLevelOpen = false; + if (inList) { + result += '\n'; + inList = false; } - result += line; + result += `${line}\n`; } }); - if (isSecondLevelOpen) result += ''; - if (isFirstLevelOpen) result += ''; + if (inSubList) result += '\n'; + if (inList) result += '\n'; return result; -}; +} const parseMarkdown = (content: string) => { return parseLists(