From 923cf3522c001539bcf33b47d84efe093a8e7db5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 Jul 2009 14:17:47 -0600 Subject: [PATCH] EPUB Output: Remove hyperlinks with no content as they cause rendering artifacts in browser based renderers --- src/calibre/ebooks/epub/output.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/calibre/ebooks/epub/output.py b/src/calibre/ebooks/epub/output.py index 18009a9a9f..d8bab20b1c 100644 --- a/src/calibre/ebooks/epub/output.py +++ b/src/calibre/ebooks/epub/output.py @@ -148,6 +148,20 @@ class EPUBOutput(OutputFormatPlugin): if not pre.text and len(pre) == 0: pre.tag = 'div' + # Remove hyperlinks with no content as they cause rendering + # artifacts in browser based renderers + for a in body.xpath('//a[@href]'): + if a.get('id', None) is None and a.get('name', None) is None \ + and len(a) == 0 and not a.text: + p = a.getparent() + idx = p.index(a) -1 + p.remove(a) + if a.tail: + if idx <= 0: + p.text += a.tail + else: + p[idx].tail += a.tail + def convert(self, oeb, output_path, input_plugin, opts, log): self.log, self.opts, self.oeb = log, opts, oeb