From c9676e17a7e91a0d6e8644bfd78ee2ac72db9e8f Mon Sep 17 00:00:00 2001 From: Lion Arar Date: Wed, 15 Oct 2025 11:16:45 -0400 Subject: [PATCH] style: modified returned markdown to be more user-friendly. --- src/modules/chatbot/components/dialogue-phrase.vue | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/chatbot/components/dialogue-phrase.vue b/src/modules/chatbot/components/dialogue-phrase.vue index 042117f..d196ae5 100644 --- a/src/modules/chatbot/components/dialogue-phrase.vue +++ b/src/modules/chatbot/components/dialogue-phrase.vue @@ -9,7 +9,7 @@ const props = defineProps<{ // Initialize Markdown parser const md = new MarkdownIt({ - breaks: true, // Support line breaks + breaks: false, // Support line breaks linkify: true, // Make URLs clickable html: false // Prevent raw HTML injection }) @@ -17,7 +17,11 @@ const md = new MarkdownIt({ // Removes all the h1,h2,h3 to make the Md more user friendly const cleanMarkdown = (markdown: string): string => { if (!markdown) return '' - return markdown.replace(/^#{1,3}\s(.*)$/gm, '#### $1') + return markdown + .replace(/\r\n/g, '\n') // normalize Windows line endings + .replace(/([.!?])(\s+)(?=[A-Z])/g, '$1\n') // insert line break after sentence-ending punctuation + .replace(/\n{3,}/g, '\n\n') // squash triple+ line breaks + .replace(/^#{1,3}\s(.*)$/gm, '#### $1') // downgrade headings } // Compute parsed content