From 7793830e60b4e6aa5ff873c9f7195f8f1253f22a Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 16 Oct 2017 13:03:38 +0300 Subject: [PATCH] [Sync] Kazimir fixing quotes inside links improved to work with begining of text --- utils/Sync/kazimir/__init__.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/utils/Sync/kazimir/__init__.py b/utils/Sync/kazimir/__init__.py index 440d5444..881bfc75 100644 --- a/utils/Sync/kazimir/__init__.py +++ b/utils/Sync/kazimir/__init__.py @@ -45,6 +45,8 @@ def clean_tree(tree): def fix_links_quotes(tree): + safe = lambda x: x if x else '' + for link in tree.iterlinks(): a = link[0] if a.tag != 'a': @@ -58,13 +60,10 @@ def fix_links_quotes(tree): a.text = a.text[1:-1] # Move first quote out of A to the prefix - a.getparent().text = a.getparent().text + quote[0] + a.getparent().text = safe(a.getparent().text) + quote[0] # Move last quote out of A to the suffix - if a.tail: - a.tail = quote[1] + a.tail - else: - a.tail = quote[1] + a.tail = quote[1] + safe(a.tail) return tree