import { Fragment } from "react";
function inline(text, keyPrefix) {
const pattern = /(\*\*[^*]+\*\*|\*[^*]+\*|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^)\s]+\))/g;
const nodes = [];
let last = 0;
let index = 0;
for (const match of text.matchAll(pattern)) {
if (match.index > last) nodes.push(text.slice(last, match.index));
const token = match[0];
const key = `${keyPrefix}-${index}`;
if (token.startsWith("**")) nodes.push({token.slice(2, -2)});
else if (token.startsWith("*")) nodes.push({token.slice(1, -1)});
else if (token.startsWith("`")) nodes.push({token.slice(1, -1)});
else {
const linked = token.match(/^\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)$/);
if (linked) {
nodes.push({linked[1]});
}
}
last = match.index + token.length;
index += 1;
}
if (last < text.length) nodes.push(text.slice(last));
return nodes;
}
export function MarkdownView({ text }) {
const lines = String(text || "").replace(/\r\n/g, "\n").split("\n");
const blocks = [];
let list = null;
function closeList() {
if (!list) return;
const items = list.items.map((item, index) =>
{inline(line, `p-${index}`)}
); }); closeList(); return