diff --git a/se/easy_xml.py b/se/easy_xml.py index 74730a72..b2d8680e 100644 --- a/se/easy_xml.py +++ b/se/easy_xml.py @@ -231,16 +231,13 @@ def _replace_shorthand_namespaces(self, value:str) -> str: shorthand namespaces. Example: - epub:type -> {http://www.idpf.org/2007/ops}:type + epub:type -> {http://www.idpf.org/2007/ops}type """ - output = value - if self.namespaces: - for name, identifier in self.namespaces.items(): - output = regex.sub(fr"^{name}:", f"{{{identifier}}}", output) + value = regex.sub(r"^(\L):", lambda m: f"{{{self.namespaces[m[1]]}}}", value, ns=self.namespaces.keys()) - return output + return value def to_tag_string(self) -> str: """