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
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<!-- Text (Markdown) -->
<MarkdownRender
v-else-if="renderPart.part.type === 'plain' && renderPart.part.text && renderPart.part.text.trim()"
custom-id="message-list" :custom-html-tags="['ref']" :content="renderPart.part.text" :typewriter="false"
custom-id="message-list" :custom-html-tags="['ref']" :content="normalizeMarkdownContent(renderPart.part.text)" :typewriter="false"
class="markdown-content" :is-dark="isDark" :monacoOptions="{ theme: isDark ? 'vs-dark' : 'vs-light' }" />

<!-- Image -->
Expand Down Expand Up @@ -151,6 +151,21 @@ const emitDownloadFile = (file) => {
emit('download-file', file);
};

const FULL_HTML_DOCUMENT_RE = /^\s*(?:<!doctype\s+html[^>]*>\s*)?<html\b[\s\S]*<\/html>\s*$/i;

const normalizeMarkdownContent = (text) => {
if (typeof text !== 'string') {
return text;
}

const trimmed = text.trim();
if (!trimmed || !FULL_HTML_DOCUMENT_RE.test(trimmed)) {
return text;
}

return `\`\`\`html\n${trimmed}\n\`\`\``;
};

const formatDuration = (seconds) => {
if (seconds < 1) {
return `${Math.round(seconds * 1000)}ms`;
Expand Down