mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-12 23:02:35 +00:00
feat: render Markdown in citations (Fixes #23679)
This commit is contained in:
parent
2b26355002
commit
8ba9045973
2 changed files with 31 additions and 1 deletions
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
import Textarea from '$lib/components/common/Textarea.svelte';
|
||||
import Markdown from '$lib/components/chat/Messages/Markdown.svelte';
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
|
|
@ -87,6 +88,24 @@
|
|||
|
||||
return fragment ? `${baseUrl}#:~:text=${fragment}` : baseUrl;
|
||||
};
|
||||
|
||||
const hasMarkdownSyntax = (text: string): boolean => {
|
||||
if (!text) return false;
|
||||
// Check for common markdown patterns
|
||||
const markdownPatterns = [
|
||||
/^#{1,6}\s/m, // Headers
|
||||
/\|.+\|/, // Tables
|
||||
/^[-*+]\s/m, // Unordered lists
|
||||
/^\d+\.\s/m, // Ordered lists
|
||||
/^>\s/m, // Blockquotes
|
||||
/\*\*.+\*\*/, // Bold
|
||||
/__.+__/, // Bold (underscore)
|
||||
/\*.+\*/, // Italic
|
||||
/\[.+\]\(.+\)/, // Links
|
||||
/`{1,3}.+`{1,3}/ // Code
|
||||
];
|
||||
return markdownPatterns.some(pattern => pattern.test(text));
|
||||
};
|
||||
</script>
|
||||
|
||||
<Modal size="lg" bind:show>
|
||||
|
|
@ -215,6 +234,15 @@
|
|||
srcdoc={document.document}
|
||||
title={$i18n.t('Content')}
|
||||
></iframe>
|
||||
{:else if hasMarkdownSyntax(document.document)}
|
||||
<div class="prose dark:prose-invert prose-table:border-collapse prose-table:w-full prose-th:border prose-th:border-gray-300 dark:prose-th:border-gray-600 prose-th:px-2 prose-th:py-1 prose-td:border prose-td:border-gray-300 dark:prose-td:border-gray-600 prose-td:px-2 prose-td:py-1 max-w-none text-sm break-words overflow-hidden">
|
||||
<Markdown
|
||||
id={`citation-${documentIdx}`}
|
||||
content={document.document}
|
||||
done={true}
|
||||
editCodeBlock={false}
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
<pre class="text-sm dark:text-gray-400 whitespace-pre-line">{document.document
|
||||
.trim()
|
||||
|
|
|
|||
|
|
@ -37,7 +37,9 @@
|
|||
|
||||
const options = {
|
||||
throwOnError: false,
|
||||
breaks: true
|
||||
breaks: true,
|
||||
gfm: true,
|
||||
tables: true
|
||||
};
|
||||
|
||||
marked.use(markedKatexExtension(options));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue