From 927744673ef4ce3469a51ed5a898c6c7c78bfee1 Mon Sep 17 00:00:00 2001 From: adar2378 Date: Sun, 5 Apr 2026 22:31:26 +0600 Subject: [PATCH] Fix ValueError in remove_namespaces when tag name contains colon When an EPUB contains elements with custom namespace prefixes (e.g. ), the remove_namespaces method in the KF8 writer crashes with `ValueError: Invalid tag name 'vita:'`. The existing except ValueError block only strips colons from attribute names but does not handle the tag name itself. This causes the second makeelement call to raise the same ValueError. Fix: replace colons with hyphens in the tag name before retrying, consistent with how colon-containing attributes are already handled. --- src/calibre/ebooks/mobi/writer8/skeleton.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/ebooks/mobi/writer8/skeleton.py b/src/calibre/ebooks/mobi/writer8/skeleton.py index b5e28088f4..31bc997822 100644 --- a/src/calibre/ebooks/mobi/writer8/skeleton.py +++ b/src/calibre/ebooks/mobi/writer8/skeleton.py @@ -246,6 +246,8 @@ class Chunker: try: elem = nroot.makeelement(tn, attrib=attrib) except ValueError: + if ':' in tn: + tn = tn.replace(':', '-') attrib = {k:v for k, v in attrib.items() if ':' not in k} elem = nroot.makeelement(tn, attrib=attrib) elem.text = tag.text