fix(chat): stop loading bubble early, no tab switch on inject, convert md->html in richtext

This commit is contained in:
2026-05-03 00:55:02 +02:00
parent ad3af531b8
commit afa8043fd5
2 changed files with 38 additions and 5 deletions

View File

@@ -56,6 +56,30 @@ import { useSession } from 'next-auth/react'
import { useSearchParams } from 'next/navigation'
import { useLanguage } from '@/lib/i18n'
/** Convert basic markdown to HTML for richtext injection from AI chat */
function markdownToBasicHtml(md: string): string {
return md
.replace(/^#{6}\s(.+)$/gm, '<h6>$1</h6>')
.replace(/^#{5}\s(.+)$/gm, '<h5>$1</h5>')
.replace(/^#{4}\s(.+)$/gm, '<h4>$1</h4>')
.replace(/^#{3}\s(.+)$/gm, '<h3>$1</h3>')
.replace(/^#{2}\s(.+)$/gm, '<h2>$1</h2>')
.replace(/^#\s(.+)$/gm, '<h1>$1</h1>')
.replace(/\*\*\*(.+?)\*\*\*/g, '<strong><em>$1</em></strong>')
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
.replace(/\*(.+?)\*/g, '<em>$1</em>')
.replace(/__(.+?)__/g, '<strong>$1</strong>')
.replace(/_(.+?)_/g, '<em>$1</em>')
.replace(/`([^`]+)`/g, '<code>$1</code>')
.replace(/~~(.+?)~~/g, '<s>$1</s>')
.replace(/^[-*]\s(.+)$/gm, '<li>$1</li>')
.replace(/^\d+\.\s(.+)$/gm, '<li>$1</li>')
.replace(/^>\s(.+)$/gm, '<blockquote>$1</blockquote>')
.replace(/\n{2,}/g, '</p><p>')
.replace(/^(?!<[hH1-6]|<blockquote|<li|<pre|<p)(.+)$/gm, '<p>$1</p>')
.replace(/<p><\/p>/g, '')
}
interface HistoryState {
title: string
content: string
@@ -1044,7 +1068,15 @@ export function NoteInput({
noteTitle={title}
noteContent={content}
noteImages={allImages}
onApplyToNote={(newContent) => setContent(newContent)}
onApplyToNote={(newContent) => {
if (type === 'richtext') {
// If content looks like markdown, convert to HTML before injecting into richtext
const looksLikeMarkdown = /^#{1,6}\s|^[-*]\s|\*\*[^*]+\*\*|^>\s/.test(newContent)
setContent(looksLikeMarkdown ? markdownToBasicHtml(newContent) : newContent)
} else {
setContent(newContent)
}
}}
lastActionApplied={false}
notebooks={notebooks.map(nb => ({ id: nb.id, name: nb.name }))}
className="border border-border border-l-0 rounded-r-xl overflow-hidden shadow-sm"