From 1dc5452cd0f8bdc03c016dd8433ec131d9bdc541 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 2 Mar 2025 08:46:31 +0100 Subject: [PATCH] refactor(read_only_code): add comment about potential bug will need to be confirmed first though, by the unit tests that I will write --- src/public/app/widgets/type_widgets/read_only_code.ts | 7 +++++++ 1 file changed, 7 insertions(+) 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 b6a992c89..400513516 100644 --- a/src/public/app/widgets/type_widgets/read_only_code.ts +++ b/src/public/app/widgets/type_widgets/read_only_code.ts @@ -70,6 +70,13 @@ export default class ReadOnlyCodeTypeWidget extends AbstractCodeTypeWidget { html = html // match everything, including whitespace/newline characters + // TriliumNextTODO: this only seems to replace the very first occurence of a "pre" tag. + // => the i++ makes it look like this isn't on purpose though. + // The "dot" is also matching too greedy, i.e. it matches everything in between the first and last pre tag, + // even if there other pre-tags nested (which is valid HTML apparently). The fix would be: + // a) add the g flag for matching more than one ocurrence + // b) add "?" as lazy quantifier after the "+" like so + // /
((.)+?)<\/pre>/g
             .replace(/
((.)+)?<\/pre>/s, (match) => {
                 pre.push({ indent: "", tag: match });
                 return `<--TEMPPRE${i++}/-->`;