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
This commit is contained in:
Panagiotis Papadopoulos 2025-03-01 09:16:44 +01:00
parent 3fec958fb3
commit 480f1e4ce1

View File

@ -67,9 +67,10 @@ export default class ReadOnlyCodeTypeWidget extends AbstractCodeTypeWidget {
let pre: { indent: string; tag: string }[] = [];
html = html
.replace(new RegExp("<pre>((.|\\t|\\n|\\r)+)?</pre>"), function (x) {
pre.push({ indent: "", tag: x });
return "<--TEMPPRE" + i++ + "/-->";
// match everything, including whitespace/newline characters
.replace(/<pre>((.)+)?<\/pre>/s, (match) => {
pre.push({ indent: "", tag: match });
return `<--TEMPPRE${i++}/-->`;
})
.replace(new RegExp("<[^<>]+>[^<]?", "g"), function (x) {
let ret;