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,27 +152,31 @@ class CHMInput(InputFormatPlugin):
|
|||||||
#print "============================="
|
#print "============================="
|
||||||
log.debug('Found %d section nodes' % len(chapters))
|
log.debug('Found %d section nodes' % len(chapters))
|
||||||
htmlpath = os.path.splitext(hhcpath)[0] + ".html"
|
htmlpath = os.path.splitext(hhcpath)[0] + ".html"
|
||||||
f = open(htmlpath, 'wb')
|
with open(htmlpath, 'wb') as f:
|
||||||
if chapters:
|
if chapters:
|
||||||
f.write('<html><head><meta http-equiv="Content-type"'
|
f.write('<html><head><meta http-equiv="Content-type"'
|
||||||
' content="text/html;charset=UTF-8" /></head><body>\n')
|
' content="text/html;charset=UTF-8" /></head><body>\n')
|
||||||
path0 = chapters[0][1]
|
path0 = chapters[0][1]
|
||||||
subpath = os.path.dirname(path0)
|
subpath = os.path.dirname(path0)
|
||||||
|
base = os.path.dirname(f.name)
|
||||||
|
|
||||||
for chapter in chapters:
|
for chapter in chapters:
|
||||||
title = chapter[0]
|
title = chapter[0]
|
||||||
rsrcname = os.path.basename(chapter[1])
|
rsrcname = os.path.basename(chapter[1])
|
||||||
rsrcpath = os.path.join(subpath, rsrcname)
|
rsrcpath = os.path.join(subpath, rsrcname)
|
||||||
# title should already be url encoded
|
if (not os.path.exists(os.path.join(base, rsrcpath)) and
|
||||||
url = "<br /><a href=" + rsrcpath + ">" + title + " </a>\n"
|
os.path.exists(os.path.join(base, chapter[1]))):
|
||||||
if isinstance(url, unicode):
|
rsrcpath = chapter[1]
|
||||||
url = url.encode('utf-8')
|
|
||||||
f.write(url)
|
|
||||||
|
|
||||||
f.write("</body></html>")
|
# title should already be url encoded
|
||||||
else:
|
url = "<br /><a href=" + rsrcpath + ">" + title + " </a>\n"
|
||||||
f.write(hhcdata)
|
if isinstance(url, unicode):
|
||||||
f.close()
|
url = url.encode('utf-8')
|
||||||
|
f.write(url)
|
||||||
|
|
||||||
|
f.write("</body></html>")
|
||||||
|
else:
|
||||||
|
f.write(hhcdata)
|
||||||
return htmlpath
|
return htmlpath
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user