From 25b01cbddad23bbbb547a3ae0eb10c3d484eb379 Mon Sep 17 00:00:00 2001 From: Kiryl Date: Thu, 29 Sep 2022 11:20:59 +0300 Subject: [PATCH] improve attributes mover --- src/html_presets_processor.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/html_presets_processor.py b/src/html_presets_processor.py index eeba3ca..cfffe7b 100644 --- a/src/html_presets_processor.py +++ b/src/html_presets_processor.py @@ -27,8 +27,14 @@ class HtmlPresetsProcessor: kwargs["rule"]["tag_to_wrap"])) @staticmethod - def _decompose_tag(**kwargs): - kwargs["tag"].parent.attrs.update(kwargs["tag"].attrs) + def set_attrs_to_parent(tag, parent_tag): + for key in tag.attrs: + if key not in parent_tag.attrs: + parent_tag.attrs[key] = tag.attrs[key] + + def _decompose_tag(self, **kwargs): + if kwargs["tag"].parent: + self.set_attrs_to_parent(kwargs["tag"], kwargs["tag"].parent) kwargs["tag"].decompose() @staticmethod @@ -111,9 +117,9 @@ class HtmlPresetsProcessor: elif attr: del kwargs["tag"][attr] - @staticmethod - def _unwrap_tag(**kwargs): - kwargs["tag"].parent.attrs.update(kwargs["tag"].attrs) + def _unwrap_tag(self, **kwargs): + if kwargs["tag"].parent: + self.set_attrs_to_parent(kwargs["tag"], kwargs["tag"].parent) kwargs["tag"].unwrap() @staticmethod