Timothy Jaeryang Baek 3 months ago
parent
commit
b93ee37f9a

+ 25 - 27
src/lib/components/common/RichTextInput.svelte

@@ -1,5 +1,30 @@
 <script lang="ts">
 	import { marked } from 'marked';
+	marked.use({
+		breaks: 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>`;
+			}
+		}
+	});
 
 	import TurndownService from 'turndown';
 	import { gfm } from 'turndown-plugin-gfm';
@@ -271,33 +296,6 @@
 		const { state, view } = editor;
 		const { schema, tr } = state;
 
-		// Configure marked with extensions
-		marked.use({
-			breaks: 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);
 

+ 27 - 0
src/lib/components/notes/NoteEditor/Chat.svelte

@@ -3,6 +3,33 @@
 	export let selectedModelId = '';
 
 	import { marked } from 'marked';
+	// Configure marked with extensions
+	marked.use({
+		breaks: 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>`;
+			}
+		}
+	});
+
 	import { toast } from 'svelte-sonner';
 
 	import { goto } from '$app/navigation';