mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
CHM Input: Fix ToC entries that use fragments not supported. Fixes #2024139 [Private bug](https://bugs.launchpad.net/calibre/+bug/2024139)
This commit is contained in:
parent
e0dee4fdef
commit
505980a60a
@ -133,17 +133,21 @@ class CHMInput(InputFormatPlugin):
|
||||
return _unquote(x).decode('utf-8')
|
||||
|
||||
def unquote_path(x):
|
||||
x, _, frag = x.partition('#')
|
||||
if frag:
|
||||
frag = '#' + frag
|
||||
if not os.path.exists(os.path.join(base, x)):
|
||||
y = unquote(x)
|
||||
if (not os.path.exists(os.path.join(base, x)) and os.path.exists(os.path.join(base, y))):
|
||||
if os.path.exists(os.path.join(base, y)):
|
||||
x = y
|
||||
return x
|
||||
return x, frag
|
||||
|
||||
def donode(item, parent, base, subpath):
|
||||
for child in item:
|
||||
title = child.title
|
||||
if not title:
|
||||
continue
|
||||
raw = unquote_path(child.href or '')
|
||||
raw, frag = unquote_path(child.href or '')
|
||||
rsrcname = os.path.basename(raw)
|
||||
rsrcpath = os.path.join(subpath, rsrcname)
|
||||
if (not os.path.exists(os.path.join(base, rsrcpath)) and os.path.exists(os.path.join(base, raw))):
|
||||
@ -153,7 +157,7 @@ class CHMInput(InputFormatPlugin):
|
||||
rsrcpath = urlquote(rsrcpath)
|
||||
if not raw:
|
||||
rsrcpath = ''
|
||||
c = DIV(A(title, href=rsrcpath))
|
||||
c = DIV(A(title, href=rsrcpath + frag))
|
||||
donode(child, c, base, subpath)
|
||||
parent.append(c)
|
||||
|
||||
@ -161,7 +165,7 @@ class CHMInput(InputFormatPlugin):
|
||||
if toc.count() > 1:
|
||||
from lxml.html.builder import HTML, BODY, DIV, A
|
||||
path0 = toc[0].href
|
||||
path0 = unquote_path(path0)
|
||||
path0 = unquote_path(path0)[0]
|
||||
subpath = os.path.dirname(path0)
|
||||
base = os.path.dirname(f.name)
|
||||
root = DIV()
|
||||
|
Loading…
x
Reference in New Issue
Block a user