From 02d2f381b9539e2edcbe13c2ae5d42b5e4d24104 Mon Sep 17 00:00:00 2001 From: Ovidijus Parsiunas Date: Wed, 3 Jul 2024 13:52:15 +0100 Subject: [PATCH] new line rendering fix for code --- component/src/views/chat/messages/messagesBase.ts | 6 ++---- .../src/views/chat/messages/remarkable/remarkableConfig.ts | 3 ++- .../src/views/chat/messages/remarkable/remarkableUtils.ts | 7 ------- 3 files changed, 4 insertions(+), 12 deletions(-) delete mode 100644 component/src/views/chat/messages/remarkable/remarkableUtils.ts diff --git a/component/src/views/chat/messages/messagesBase.ts b/component/src/views/chat/messages/messagesBase.ts index d84c9bb9..e8b5438f 100644 --- a/component/src/views/chat/messages/messagesBase.ts +++ b/component/src/views/chat/messages/messagesBase.ts @@ -4,7 +4,6 @@ import {ProcessedTextToSpeechConfig} from './textToSpeech/textToSpeech'; import {ElementUtils} from '../../../utils/element/elementUtils'; import {HTMLDeepChatElements} from './html/htmlDeepChatElements'; import {RemarkableConfig} from './remarkable/remarkableConfig'; -import {RemarkableUtils} from './remarkable/remarkableUtils'; import {FireEvents} from '../../../utils/events/fireEvents'; import {HTMLClassUtilities} from '../../../types/html'; import {MessageStyleUtils} from './messageStyleUtils'; @@ -167,11 +166,10 @@ export class MessagesBase { } public renderText(bubbleElement: HTMLElement, text: string) { - const processedText = RemarkableUtils.replaceNewlineWithDouble(text); - bubbleElement.innerHTML = this._remarkable.render(processedText); + bubbleElement.innerHTML = this._remarkable.render(text); // there is a bug in remarkable where text with only numbers and full stop after them causes the creation // of a list which has no innert text and is instead prepended as a prefix in the start attribute (12.) - if (bubbleElement.innerText.trim().length === 0) bubbleElement.innerText = processedText; + if (bubbleElement.innerText.trim().length === 0) bubbleElement.innerText = text; } // this is mostly used for enabling highlight.js to highlight code if it downloads later diff --git a/component/src/views/chat/messages/remarkable/remarkableConfig.ts b/component/src/views/chat/messages/remarkable/remarkableConfig.ts index 8a967fee..cd755200 100644 --- a/component/src/views/chat/messages/remarkable/remarkableConfig.ts +++ b/component/src/views/chat/messages/remarkable/remarkableConfig.ts @@ -29,13 +29,14 @@ export class RemarkableConfig { }, html: false, // Enable HTML tags in source xhtmlOut: false, // Use '/' to close single tags (
) - breaks: false, // Convert '\n' in paragraphs into
+ breaks: true, // Convert '\n' in paragraphs into
langPrefix: 'language-', // CSS language prefix for fenced blocks linkTarget: '_blank', // set target to open in a new tab typographer: true, // Enable smartypants and other sweet transforms }); } else { return new Remarkable({ + breaks: true, linkTarget: '_blank', // set target to open in a new tab }); } diff --git a/component/src/views/chat/messages/remarkable/remarkableUtils.ts b/component/src/views/chat/messages/remarkable/remarkableUtils.ts deleted file mode 100644 index 82ebec04..00000000 --- a/component/src/views/chat/messages/remarkable/remarkableUtils.ts +++ /dev/null @@ -1,7 +0,0 @@ -export class RemarkableUtils { - // this is to allow remarkable to render \n as a new line: - // it operates by replacing \n with \n\n - public static replaceNewlineWithDouble(str: string) { - return str.replace(/(?