mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-15 05:45:19 +00:00
refac: task list handling
This commit is contained in:
parent
e37e6e6b03
commit
bdab9dd596
1 changed files with 27 additions and 3 deletions
|
|
@ -271,12 +271,36 @@
|
||||||
const { state, view } = editor;
|
const { state, view } = editor;
|
||||||
const { schema, tr } = state;
|
const { schema, tr } = state;
|
||||||
|
|
||||||
// If content is a string, convert it to a ProseMirror node
|
// Configure marked with extensions
|
||||||
const htmlContent = marked.parse(content, {
|
marked.use({
|
||||||
breaks: true,
|
breaks: true,
|
||||||
gfm: true
|
gfm: true,
|
||||||
|
renderer: {
|
||||||
|
list(body, ordered, start) {
|
||||||
|
const isTaskList = body.includes('data-checked=');
|
||||||
|
|
||||||
|
if (isTaskList) {
|
||||||
|
return `<ul data-type="taskList">${body}</ul>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const type = ordered ? 'ol' : 'ul';
|
||||||
|
const startatt = ordered && start !== 1 ? ` start="${start}"` : '';
|
||||||
|
return `<${type}${startatt}>${body}</${type}>`;
|
||||||
|
},
|
||||||
|
|
||||||
|
listitem(text, task, checked) {
|
||||||
|
if (task) {
|
||||||
|
const checkedAttr = checked ? 'true' : 'false';
|
||||||
|
return `<li data-type="taskItem" data-checked="${checkedAttr}">${text}</li>`;
|
||||||
|
}
|
||||||
|
return `<li>${text}</li>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If content is a string, convert it to a ProseMirror node
|
||||||
|
const htmlContent = marked.parse(content);
|
||||||
|
|
||||||
// insert the HTML content at the current selection
|
// insert the HTML content at the current selection
|
||||||
editor.commands.insertContent(htmlContent);
|
editor.commands.insertContent(htmlContent);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue