mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
CHM Input: Fix handling of chm files that split their html into multiple sub-directories. Fixes #1018792 (CHM ToC generated incorrectly)
This commit is contained in:
parent
d20bd1f8b1
commit
2b4307fc7f
@ -152,17 +152,22 @@ class CHMInput(InputFormatPlugin):
|
||||
#print "============================="
|
||||
log.debug('Found %d section nodes' % len(chapters))
|
||||
htmlpath = os.path.splitext(hhcpath)[0] + ".html"
|
||||
f = open(htmlpath, 'wb')
|
||||
with open(htmlpath, 'wb') as f:
|
||||
if chapters:
|
||||
f.write('<html><head><meta http-equiv="Content-type"'
|
||||
' content="text/html;charset=UTF-8" /></head><body>\n')
|
||||
path0 = chapters[0][1]
|
||||
subpath = os.path.dirname(path0)
|
||||
base = os.path.dirname(f.name)
|
||||
|
||||
for chapter in chapters:
|
||||
title = chapter[0]
|
||||
rsrcname = os.path.basename(chapter[1])
|
||||
rsrcpath = os.path.join(subpath, rsrcname)
|
||||
if (not os.path.exists(os.path.join(base, rsrcpath)) and
|
||||
os.path.exists(os.path.join(base, chapter[1]))):
|
||||
rsrcpath = chapter[1]
|
||||
|
||||
# title should already be url encoded
|
||||
url = "<br /><a href=" + rsrcpath + ">" + title + " </a>\n"
|
||||
if isinstance(url, unicode):
|
||||
@ -172,7 +177,6 @@ class CHMInput(InputFormatPlugin):
|
||||
f.write("</body></html>")
|
||||
else:
|
||||
f.write(hhcdata)
|
||||
f.close()
|
||||
return htmlpath
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user