/**
* Markdown renderer for the nextgen architecture docs.
* Adapted from components/vitis/Markdown.tsx (which is read-only for this
* feature) with GFM table support added — the architecture docs are
* table-heavy comparison matrices.
*/
import Box from '@mui/material/Box';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import Typography from '@mui/material/Typography';
function Inline({ text }: { text: string }) {
const parts = text.split(/(\*\*[^*]+\*\*|`[^`]+`)/g).filter(Boolean);
return (
<>
{parts.map((p, i) => {
if (p.startsWith('**') && p.endsWith('**')) {
return {p.slice(2, -2)};
}
if (p.startsWith('`') && p.endsWith('`')) {
return (
{p.slice(1, -1)}
);
}
return {p};
})}
>
);
}
function splitRow(line: string): string[] {
return line.replace(/^\s*\|/, '').replace(/\|\s*$/, '').split('|').map((c) => c.trim());
}
export default function Markdown({ source }: { source: string }) {
const lines = source.split('\n');
const blocks: React.ReactNode[] = [];
let i = 0;
let key = 0;
while (i < lines.length) {
const line = lines[i];
if (line.startsWith('```')) {
const code: string[] = [];
i += 1;
while (i < lines.length && !lines[i].startsWith('```')) {
code.push(lines[i]);
i += 1;
}
i += 1;
blocks.push(
{code.join('\n')}
);
continue;
}
if (/^\s*\|.*\|\s*$/.test(line) && i + 1 < lines.length && /^\s*\|[\s:|-]+\|\s*$/.test(lines[i + 1])) {
const header = splitRow(line);
i += 2;
const rows: string[][] = [];
while (i < lines.length && /^\s*\|.*\|\s*$/.test(lines[i])) {
rows.push(splitRow(lines[i]));
i += 1;
}
blocks.push(
{header.map((h, j) => (
))}
{rows.map((r, ri) => (
{r.map((c, ci) => (
))}
))}
);
continue;
}
const h = line.match(/^(#{1,4})\s+(.*)$/);
if (h) {
const level = h[1].length;
blocks.push(
);
i += 1;
continue;
}
if (/^\s*[-*]\s+/.test(line)) {
const items: string[] = [];
while (i < lines.length && /^\s*[-*]\s+/.test(lines[i])) {
items.push(lines[i].replace(/^\s*[-*]\s+/, ''));
i += 1;
}
blocks.push(
{items.map((it, j) => (
))}
);
continue;
}
if (/^\s*\d+\.\s+/.test(line)) {
const items: string[] = [];
while (i < lines.length && /^\s*\d+\.\s+/.test(lines[i])) {
items.push(lines[i].replace(/^\s*\d+\.\s+/, ''));
i += 1;
}
blocks.push(
{items.map((it, j) => (
))}
);
continue;
}
if (line.trim() === '' || /^---+$/.test(line.trim())) {
i += 1;
continue;
}
const para: string[] = [line];
i += 1;
while (
i < lines.length &&
lines[i].trim() !== '' &&
!/^(#{1,4}\s|```|\s*[-*]\s|\s*\d+\.\s|\s*\|)/.test(lines[i])
) {
para.push(lines[i]);
i += 1;
}
blocks.push(
);
}
return {blocks};
}