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')
|
return _unquote(x).decode('utf-8')
|
||||||
|
|
||||||
def unquote_path(x):
|
def unquote_path(x):
|
||||||
y = unquote(x)
|
x, _, frag = x.partition('#')
|
||||||
if (not os.path.exists(os.path.join(base, x)) and os.path.exists(os.path.join(base, y))):
|
if frag:
|
||||||
x = y
|
frag = '#' + frag
|
||||||
return x
|
if not os.path.exists(os.path.join(base, x)):
|
||||||
|
y = unquote(x)
|
||||||
|
if os.path.exists(os.path.join(base, y)):
|
||||||
|
x = y
|
||||||
|
return x, frag
|
||||||
|
|
||||||
def donode(item, parent, base, subpath):
|
def donode(item, parent, base, subpath):
|
||||||
for child in item:
|
for child in item:
|
||||||
title = child.title
|
title = child.title
|
||||||
if not title:
|
if not title:
|
||||||
continue
|
continue
|
||||||
raw = unquote_path(child.href or '')
|
raw, frag = unquote_path(child.href or '')
|
||||||
rsrcname = os.path.basename(raw)
|
rsrcname = os.path.basename(raw)
|
||||||
rsrcpath = os.path.join(subpath, rsrcname)
|
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))):
|
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)
|
rsrcpath = urlquote(rsrcpath)
|
||||||
if not raw:
|
if not raw:
|
||||||
rsrcpath = ''
|
rsrcpath = ''
|
||||||
c = DIV(A(title, href=rsrcpath))
|
c = DIV(A(title, href=rsrcpath + frag))
|
||||||
donode(child, c, base, subpath)
|
donode(child, c, base, subpath)
|
||||||
parent.append(c)
|
parent.append(c)
|
||||||
|
|
||||||
@ -161,7 +165,7 @@ class CHMInput(InputFormatPlugin):
|
|||||||
if toc.count() > 1:
|
if toc.count() > 1:
|
||||||
from lxml.html.builder import HTML, BODY, DIV, A
|
from lxml.html.builder import HTML, BODY, DIV, A
|
||||||
path0 = toc[0].href
|
path0 = toc[0].href
|
||||||
path0 = unquote_path(path0)
|
path0 = unquote_path(path0)[0]
|
||||||
subpath = os.path.dirname(path0)
|
subpath = os.path.dirname(path0)
|
||||||
base = os.path.dirname(f.name)
|
base = os.path.dirname(f.name)
|
||||||
root = DIV()
|
root = DIV()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user