diff --git a/mscxyz/score.py b/mscxyz/score.py index c5889b7..9cdd60b 100644 --- a/mscxyz/score.py +++ b/mscxyz/score.py @@ -185,27 +185,6 @@ def get_version(self) -> float: return version raise ValueError("Could not get version number") - def remove_tags_by_xpath(self, *xpath_strings: str) -> None: - """Remove tags by xpath strings. - - :param xpath_strings: A xpath string. - - .. code:: Python - - tree.remove_tags_by_xpath( - '/museScore/Score/Style', '//LayoutBreak', '//StemDirection' - ) - - """ - for xpath_string in xpath_strings: - x: _XPathObject = self.xml_root.xpath(xpath_string) - if isinstance(x, list): - for rm in x: - if isinstance(rm, _Element): - p: _Element | None = rm.getparent() - if isinstance(p, _Element): - p.remove(rm) - def print_diff(self) -> None: if self.__xml_string_initial is None: return diff --git a/mscxyz/style.py b/mscxyz/style.py index 650f907..5dc2cd5 100644 --- a/mscxyz/style.py +++ b/mscxyz/style.py @@ -8,7 +8,7 @@ import lxml import lxml.etree -from lxml.etree import _Attrib, _Element, strip_tags +from lxml.etree import _Attrib, _Element from mscxyz import utils from mscxyz.utils import INCH @@ -244,9 +244,15 @@ def clean(self) -> None: """Remove the style, the layout breaks, the stem directions and the ``font``, ``b``, ``i``, ``pos``, ``offset`` tags""" self.score.xml.remove_tags( - "./Score/Style", ".//LayoutBreak", ".//StemDirection" + "./Score/Style", + ".//LayoutBreak", + ".//StemDirection", + ".//font", + ".//b", + ".//i", + ".//pos", + ".//offset", ) - strip_tags(self.score.xml_root, "font", "b", "i", "pos", "offset") def get(self, style_name: str, raise_exception: bool = True) -> str | None: """ diff --git a/mscxyz/xml.py b/mscxyz/xml.py index e8b9755..9e885ca 100644 --- a/mscxyz/xml.py +++ b/mscxyz/xml.py @@ -7,7 +7,7 @@ import lxml import lxml.etree -from lxml.etree import _Element, _ElementTree, strip_tags +from lxml.etree import _Element, _ElementTree if typing.TYPE_CHECKING: from lxml.etree import _DictAnyStr, _XPathObject @@ -331,8 +331,3 @@ def remove_tags_by_xpath(self, *xpath_strings: str) -> None: p: _Element | None = rm.getparent() if isinstance(p, _Element): p.remove(rm) - - def strip_tags(self, *tag_names: str) -> Xml: - """TODO remove. Use remove_tags instead.""" - strip_tags(self.root, *tag_names) - return self diff --git a/tests/test_xml.py b/tests/test_xml.py index b85364d..5a39831 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -104,17 +104,3 @@ def test_with_text(self, custom_xml: Xml) -> None: def test_navigate_in_tree(self, custom_xml: Xml) -> None: assert "" in custom_xml.remove_tags("./a/b").tostring() - - -class TestStripTags: - def test_element_with_childs(self, custom_xml: Xml) -> None: - custom_xml.strip_tags("a") - assert "some text" in custom_xml.tostring() - - def test_child_element(self, custom_xml: Xml) -> None: - custom_xml.strip_tags("b", "c", "d") - assert "some text" in custom_xml.tostring() - - def test_containing_text(self, custom_xml: Xml) -> None: - custom_xml.strip_tags("d") - assert "some text" in custom_xml.tostring()