mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-11 22:52:54 +00:00
feat: use rich text editor for knowledge file editing
Replace the plain textarea in the knowledge base file editor drawer with the same RichTextInput (TipTap) component used by the Add Text Content modal. This resolves an inconsistency where creating new text content offered a full WYSIWYG experience while editing existing files was limited to an unstyled textarea. Also fixes a bug in RichTextInput where onValueChange bypassed markdown parsing when preserveBreaks was enabled, causing setContent to receive raw markdown instead of parsed HTML. This collapsed all content into a single paragraph on reactive updates.
This commit is contained in:
parent
b65accae45
commit
2ff86d8c5d
2 changed files with 14 additions and 12 deletions
|
|
@ -1217,11 +1217,9 @@
|
|||
} else {
|
||||
if (value !== mdValue) {
|
||||
editor.commands.setContent(
|
||||
preserveBreaks
|
||||
? value
|
||||
: marked.parse(value.replaceAll(`\n<br/>`, `<br/>`), {
|
||||
breaks: false
|
||||
})
|
||||
marked.parse(value.replaceAll(`\n<br/>`, `<br/>`), {
|
||||
breaks: false
|
||||
})
|
||||
);
|
||||
|
||||
selectTemplate();
|
||||
|
|
|
|||
|
|
@ -171,14 +171,18 @@
|
|||
|
||||
const fileSelectHandler = async (file) => {
|
||||
try {
|
||||
selectedFile = file;
|
||||
const rawContent = selectedFile?.data?.content || '';
|
||||
const rawContent = file?.data?.content || '';
|
||||
|
||||
// Normalize single newlines to paragraph breaks (double newlines) so the
|
||||
// rich text editor's markdown parser preserves them. Without this, single
|
||||
// newlines get collapsed into spaces during markdown parsing (breaks: false).
|
||||
// Existing double+ newlines (paragraph breaks) are left unchanged.
|
||||
selectedFileContent = rawContent.replace(/(?<!\n)\n(?!\n)/g, '\n\n');
|
||||
// Strip carriage returns and normalize single newlines to paragraph
|
||||
// breaks (double newlines) so the rich text editor's markdown parser
|
||||
// preserves them. This is idempotent — already-doubled newlines are
|
||||
// left unchanged, so re-opening saved content doesn't compound.
|
||||
const normalized = rawContent.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
||||
selectedFileContent = normalized.replace(/(?<!\n)\n(?!\n)/g, '\n\n');
|
||||
|
||||
// Set selectedFile AFTER content so the {#key selectedFile.id} block
|
||||
// recreates RichTextInput with the already-normalized value.
|
||||
selectedFile = file;
|
||||
} catch (e) {
|
||||
toast.error($i18n.t('Failed to load file content.'));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue