Skip to content

Commit

Permalink
feat(ref): added support bold text & list in md
Browse files Browse the repository at this point in the history
  • Loading branch information
TrofimovAnton85 committed Sep 27, 2024
1 parent b1b4766 commit b887b94
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
48 changes: 45 additions & 3 deletions src/components/ParserOpenRPC/DetailsBox/MDContent.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,51 @@
import React from "react";

const parseLists = (content: string) => {
const lines = content.split('\n');
let result = '';
let isFirstLevelOpen = false;
let isSecondLevelOpen = false;
lines.forEach((line) => {
if (line.match(/^ {2}-\s+/)) {
if (!isSecondLevelOpen) {
result += '<ul>';
isSecondLevelOpen = true;
}
result += `<li>${line.trim().substring(4)}</li>`;
} else if (line.match(/^ -\s+/)) {
if (isSecondLevelOpen) {
result += '</ul>';
isSecondLevelOpen = false;
}
if (!isFirstLevelOpen) {
result += '<ul>';
isFirstLevelOpen = true;
}
result += `<li>${line.trim().substring(2)}</li>`;
} else {
if (isSecondLevelOpen) {
result += '</ul>';
isSecondLevelOpen = false;
}
if (isFirstLevelOpen) {
result += '</ul>';
isFirstLevelOpen = false;
}
result += line;
}
});
if (isSecondLevelOpen) result += '</ul>';
if (isFirstLevelOpen) result += '</ul>';
return result;
};

const parseMarkdown = (content: string) => {
return content
.replace(/\[(.*?)\]\((.*?)\)/g, '<a href="$2">$1</a>')
.replace(/`(.*?)`/g, "<code>$1</code>");
return parseLists(
content
.replace(/\[(.*?)\]\((.*?)\)/g, '<a href="$2">$1</a>')
.replace(/`(.*?)`/g, '<code>$1</code>')
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
);
};

interface MDContentProps {
Expand Down
2 changes: 1 addition & 1 deletion wallet/reference/new-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import { NETWORK_NAMES } from "@site/src/plugins/plugin-json-rpc"

<ParserOpenRPC
network={NETWORK_NAMES.linea}
method="eth_blockNumber"
method="eth_sendRawTransaction"
/>

0 comments on commit b887b94

Please sign in to comment.