fix(workspace): group text and code blocks cleanly under headings on paste
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 58s

This commit is contained in:
sandrodach committed 2026-10-27 21:40:51 +01:00
1 parent c85f31eee5
commit 554029a099
2 files changed
+195 -45

No files matched your search

+50 -1
View File
@@ -8,7 +8,7 @@ import React from 'react';
* - `code`
* - [label](url)
*/
export function renderInlineMarkdown(text: string): React.ReactNode[] {
function renderInlineTokens(text: string): React.ReactNode[] {
if (!text) return [];
const regex = /(`[^`]+`|\*\*[^*]+\*\*|__[^_]+__|~~[^~]+~~|\*[^*]+\*|_[^_]+_|\[([^\]]+)\]\(([^)]+)\))/g;
@@ -83,6 +83,55 @@ export function renderInlineMarkdown(text: string): React.ReactNode[] {
return elements;
}
/**
* Parses inline markdown and fenced code blocks:
* - ```lang\ncode\n```
* - **bold** or __bold__
* - *italic* or _italic_
* - ~~strikethrough~~
* - `code`
* - [label](url)
*/
export function renderInlineMarkdown(text: string): React.ReactNode[] {
if (!text) return [];
if (text.includes('```')) {
const codeBlockRegex = /(```[a-zA-Z0-9_-]*\r?\n[\s\S]*?```|```[\s\S]*?```)/g;
const parts = text.split(codeBlockRegex);
const nodes: React.ReactNode[] = [];
parts.forEach((part, partIdx) => {
if (part.startsWith('```') && part.endsWith('```')) {
const lines = part.split(/\r?\n/);
const firstLine = lines[0].slice(3).trim();
const codeLines = lines.slice(1, lines.length - 1);
const code = codeLines.join('\n');
nodes.push(
<div
key={`fenced-${partIdx}`}
className="p-2.5 my-2 rounded bg-code text-accent font-mono text-xs overflow-x-auto border border-border/60 select-text"
>
{firstLine && (
<div className="text-[10px] text-faint uppercase font-sans pb-1 select-none">
{firstLine}
</div>
)}
<pre className="whitespace-pre overflow-x-auto font-mono text-status-ok leading-relaxed">
<code>{code}</code>
</pre>
</div>
);
} else if (part) {
nodes.push(...renderInlineTokens(part));
}
});
return nodes;
}
return renderInlineTokens(text);
}
export function MarkdownViewer({ content, className = '' }: { content: string; className?: string }) {
if (!content) return null;