Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/utils/mdparser-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ export const renderMarkdown = (markdown: string): string => {
.replace(/(^-|-$)/g, '');
};

// Process code blocks - Process this first to avoid conflicts with other markdown elements
html = html.replace(
/```([\w-]*)\s*([\s\S]*?)```/gm,
function (_match, _language, codeContent) {
// Prepare the code content for display
const escapedCode = escapeHtml(codeContent.trim());

// Build the HTML for the code block without copy button
return `
<div class="relative rounded-lg overflow-hidden shadow-lg bg-gray-900">
<div class="px-2 overflow-x-auto">
<pre class="m-0 p-0"><code class="font-mono text-sm text-gray-200 block whitespace-pre overflow-visible">${escapedCode}</code></pre>
</div>
</div>
`;
},
);

// Process blockquotes
html = html.replace(/(^>.*(\n>.*)*)/gm, function (match) {
const lines = match.split('\n');
Expand Down Expand Up @@ -159,9 +177,9 @@ export const renderMarkdown = (markdown: string): string => {
'<a href="$2" class="text-blue-600 hover:underline transition-colors duration-200">$1</a>',
);

// Convert inline code
// Convert inline code - Make sure this comes after code blocks
html = html.replace(
/`(.*?)`/gim,
/`([^`]+)`/gim,
'<code class="bg-gray-100 px-1 py-0.5 rounded text-sm font-mono">$1</code>',
);

Expand Down