Files
sorsfonalak/services/frontend/src/components/Rich.tsx
T

28 lines
663 B
TypeScript
Raw Normal View History

/** Model text: `**bold**` becomes <strong>, the rest stays plain text. */
export function Rich({ text }: { text: string }) {
return (
<>
{text.split(/(\*\*[^*]+\*\*)/g).map((part, i) =>
part.startsWith("**") && part.endsWith("**") ? <strong key={i}>{part.slice(2, -2)}</strong> : part,
)}
</>
);
}
/** Paragraphs separated by blank lines. */
export function Paragraphs({ text }: { text: string }) {
return (
<>
{text
.split(/\n\s*\n/)
.map((p) => p.trim())
.filter(Boolean)
.map((p, i) => (
<p key={i}>
<Rich text={p} />
</p>
))}
</>
);
}