From 480f1e4ce19a9bdd7933968a8d222ad32be47425 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sat, 1 Mar 2025 09:16:44 +0100 Subject: [PATCH] refactor(read_only_code): simplify first format replacer * simplified regex, by using the `s` flag * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#advanced_searching_with_flags * use template literal instead of string concat * use arrow function --- src/public/app/widgets/type_widgets/read_only_code.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/public/app/widgets/type_widgets/read_only_code.ts b/src/public/app/widgets/type_widgets/read_only_code.ts index 4d7ce3ab0..24715c96b 100644 --- a/src/public/app/widgets/type_widgets/read_only_code.ts +++ b/src/public/app/widgets/type_widgets/read_only_code.ts @@ -67,9 +67,10 @@ export default class ReadOnlyCodeTypeWidget extends AbstractCodeTypeWidget { let pre: { indent: string; tag: string }[] = []; html = html - .replace(new RegExp("
((.|\\t|\\n|\\r)+)?
"), function (x) { - pre.push({ indent: "", tag: x }); - return "<--TEMPPRE" + i++ + "/-->"; + // match everything, including whitespace/newline characters + .replace(/
((.)+)?<\/pre>/s, (match) => {
+                pre.push({ indent: "", tag: match });
+                return `<--TEMPPRE${i++}/-->`;
             })
             .replace(new RegExp("<[^<>]+>[^<]?", "g"), function (x) {
                 let ret;