turash/bugulma/frontend/components/chatbot/MarkdownRenderer.tsx
Damir Mukimov 6347f42e20
Consolidate repositories: Remove nested frontend .git and merge into main repository
- Remove nested git repository from bugulma/frontend/.git
- Add all frontend files to main repository tracking
- Convert from separate frontend/backend repos to unified monorepo
- Preserve all frontend code and development history as tracked files
- Eliminate nested repository complexity for simpler development workflow

This creates a proper monorepo structure with frontend and backend
coexisting in the same repository for easier development and deployment.
2025-11-25 06:02:57 +01:00

60 lines
1.6 KiB
TypeScript

import React, { useMemo } from 'react';
interface MarkdownRendererProps {
text: string;
}
const MarkdownRenderer = ({ text }: MarkdownRendererProps) => {
const content = useMemo(() => {
if (!text) return null;
const blocks = text.split(/(\n{2,})/g);
return blocks.map((block, i) => {
if (/^\s*$/.test(block)) {
return null;
}
const lines = block.trim().split('\n');
const isList =
lines.length > 0 &&
lines.every((line) => line.trim().startsWith('* ') || line.trim().startsWith('- '));
if (isList) {
return (
<ul key={i} className="list-disc list-outside pl-5 space-y-1 my-2">
{lines.map((line, j) => {
const lineContent = line.trim().substring(2);
const boldRegex = /\*\*(.*?)\*\*/g;
const parts = lineContent.split(boldRegex);
return (
<li key={j}>
{parts.map((part, k) => (k % 2 === 1 ? <strong key={k}>{part}</strong> : part))}
</li>
);
})}
</ul>
);
} else {
const boldRegex = /\*\*(.*?)\*\*/g;
return (
<div key={i}>
{lines.map((line, j) => (
<p key={j} className="[&:not(:first-child)]:mt-2">
{line
.split(boldRegex)
.map((part, k) => (k % 2 === 1 ? <strong key={k}>{part}</strong> : part))}
</p>
))}
</div>
);
}
});
}, [text]);
return <>{content}</>;
};
export default React.memo(MarkdownRenderer);