From f5cb845659ef380855620c3a35ba6afe1c8520cb Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sat, 1 Mar 2025 09:30:35 +0100 Subject: [PATCH] refactor(read_only_code): use Set for selfClosingTags check * moved it outside of the replacer, so that it does not need get created on each iteration of the replacer (as it gets run for each single match) --- src/public/app/widgets/type_widgets/read_only_code.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 24715c96b..b317a0fb4 100644 --- a/src/public/app/widgets/type_widgets/read_only_code.ts +++ b/src/public/app/widgets/type_widgets/read_only_code.ts @@ -66,6 +66,8 @@ export default class ReadOnlyCodeTypeWidget extends AbstractCodeTypeWidget { let i = 0; let pre: { indent: string; tag: string }[] = []; + const selfClosingTags = new Set(["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr"]); + html = html // match everything, including whitespace/newline characters .replace(/
((.)+)?<\/pre>/s, (match) => {
@@ -83,7 +85,7 @@ export default class ReadOnlyCodeTypeWidget extends AbstractCodeTypeWidget {
                     pre[pInd].indent = indent;
                 }
 
-                if (["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr"].indexOf(tag) >= 0) {
+                if (selfClosingTags.has(tag)) {
                     // self closing tag
                     ret = indent + x;
                 } else {