Files
MineGeo/components/ReleaseNotes.tsx
pavel444-byte de0e891b62
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 3m40s
Add Void difficulty and publish changelogs
2026-10-20 14:05:01 +05:00

46 lines
1.3 KiB
TypeScript

import { Fragment } from "react";
// Render a small, safe subset of Discord Markdown; React escapes raw HTML.
function inline(text: string) {
return text
.split(/(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\))/g)
.map((part, i) => {
if (part.startsWith("**") && part.endsWith("**"))
return <strong key={i}>{part.slice(2, -2)}</strong>;
if (part.startsWith("`") && part.endsWith("`"))
return <code key={i}>{part.slice(1, -1)}</code>;
const link = /^\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)$/.exec(part);
if (link)
return (
<a key={i} href={link[2]} target="_blank" rel="noopener noreferrer">
{link[1]}
</a>
);
return <Fragment key={i}>{part}</Fragment>;
});
}
export function ReleaseNotes({ body }: { body: string }) {
return body.split(/\r?\n\s*\r?\n/).map((block, i) => {
const lines = block.split(/\r?\n/);
if (lines.every((line) => /^\s*[-*]\s+/.test(line)))
return (
<ul key={i}>
{lines.map((line, j) => (
<li key={j}>{inline(line.replace(/^\s*[-*]\s+/, ""))}</li>
))}
</ul>
);
return (
<p key={i}>
{lines.map((line, j) => (
<Fragment key={j}>
{j > 0 && <br />}
{inline(line)}
</Fragment>
))}
</p>
);
});
}