From 45a3bdb584d53c61d3ea869d0a5d44ae02feae4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 8 Sep 2023 13:25:05 +0200 Subject: [PATCH] formatter: Fix display of diff inside a placeable Fixes #9821 --- weblate/trans/templatetags/translations.py | 43 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/weblate/trans/templatetags/translations.py b/weblate/trans/templatetags/translations.py index 6f5b0d82dd45..c4e7e4df23df 100644 --- a/weblate/trans/templatetags/translations.py +++ b/weblate/trans/templatetags/translations.py @@ -139,6 +139,7 @@ def parse_diff(self): # noqa: C901 formatter.parse() self.tags[offset].append(f"{formatter.format()}") elif op == self.differ.DIFF_INSERT: + end = offset + len(data) # Rearrange space highlighting move_space = False start_space = -1 @@ -172,10 +173,46 @@ def parse_diff(self): # noqa: C901 self.tags[offset].append("") if move_space: self.tags[offset].append(SPACE_START) - offset += len(data) - self.tags[offset].append("") + self.tags[end].append("") if start_space != -1: - self.tags[offset].append(SPACE_START) + self.tags[end].append(SPACE_START) + + # Rearange other tags + open_tags = 0 + process = False + for i in range(offset, end + 1): + remove = [] + for pos, tag in enumerate(self.tags[i]): + if not process: + if tag.startswith(""): + break + if tag.startswith(" + remove.append(pos) + found = None + for back in range(offset - 1, 0, -1): + for child_pos, child in reversed( + list(enumerate(self.tags[back])) + ): + if child.startswith("