From 17a99627bcdd4b4f985facfc47685ba855a1629e Mon Sep 17 00:00:00 2001 From: DokoGen Date: Mon, 3 Aug 2026 16:16:22 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=82=D0=B0=D0=B1=D1=8B=20=D0=B1=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D1=88=D0=B5=20=D0=BD=D0=B5=20=D1=81=D1=8A=D0=B5?= =?UTF-8?q?=D0=B4=D0=B0=D1=8E=D1=82=D1=81=D1=8F=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B5=20=D1=86?= =?UTF-8?q?=D0=B8=D0=BA=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _normalize_loop_markers при склейке run'ов выбрасывал - теперь табы превращаются в символ \t при сборе и восстанавливаются как при пересборке параграфа --- dokogen/generator.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/dokogen/generator.py b/dokogen/generator.py index 02dc167..1520989 100644 --- a/dokogen/generator.py +++ b/dokogen/generator.py @@ -102,10 +102,15 @@ def _normalize_loop_markers(doc_xml: str) -> str: changed = False for p in root.iter(f'{{{W_NS}}}p'): - # Собираем весь текст параграфа (по всем run'ам) + # Собираем весь текст параграфа (по всем run'ам), + # табы превращаем в символ \t, чтобы не потерять texts = [] - for t in p.iter(f'{{{W_NS}}}t'): - texts.append(t.text or '') + for child in p.iter(): + tag = child.tag.split('}')[-1] + if tag == 't': + texts.append(child.text or '') + elif tag == 'tab': + texts.append('\t') full = ''.join(texts) # Интересуют параграфы с маркерами циклов ИЛИ любыми переменными {{...}} @@ -139,13 +144,19 @@ def _normalize_loop_markers(doc_xml: str) -> str: br_el = etree.SubElement(br_r, f'{{{W_NS}}}br') br_el.set(f'{{{W_NS}}}type', 'page') - # Создаём один run с полным текстом параграфа + # Создаём run с полным текстом параграфа, восстанавливая табы new_r = etree.SubElement(p, f'{{{W_NS}}}r') if rpr is not None: new_r.append(rpr) - new_t = etree.SubElement(new_r, f'{{{W_NS}}}t') - new_t.text = full - new_t.set('{http://www.w3.org/XML/1998/namespace}space', 'preserve') + # Разбиваем по \t: обычный текст → , таб → + parts = full.split('\t') + for i, part in enumerate(parts): + if part: + new_t = etree.SubElement(new_r, f'{{{W_NS}}}t') + new_t.text = part + new_t.set('{http://www.w3.org/XML/1998/namespace}space', 'preserve') + if i < len(parts) - 1: + tab_el = etree.SubElement(new_r, f'{{{W_NS}}}tab') changed = True if not changed: