This commit is contained in:
Kovid Goyal 2007-05-14 15:33:59 +00:00
parent 8c3e447dc4
commit ebe46a8c5a

View File

@ -20,7 +20,7 @@ Code to convert HTML ebooks into LRF ebooks.
I am indebted to esperanc for the initial CSS->Xylog Style conversion routines I am indebted to esperanc for the initial CSS->Xylog Style conversion routines
and to Falstaff for pylrs. and to Falstaff for pylrs.
""" """
import os, re, sys, shutil, traceback, copy import os, re, sys, shutil, traceback, copy, codecs
from htmlentitydefs import name2codepoint from htmlentitydefs import name2codepoint
from urllib import unquote from urllib import unquote
from urlparse import urlparse from urlparse import urlparse
@ -502,6 +502,8 @@ class HTMLConverter(object):
for link in self.links: for link in self.links:
para, tag = link.para, link.tag para, tag = link.para, link.tag
text = self.get_text(tag) text = self.get_text(tag)
# Needed for TOC entries due to bug in LRF
ascii_text = text.decode('utf8', 'replace').encode('ascii', 'replace')
if not text: if not text:
text = 'Link' text = 'Link'
img = tag.find('img') img = tag.find('img')
@ -521,7 +523,7 @@ class HTMLConverter(object):
if fragment in self.targets.keys(): if fragment in self.targets.keys():
tb = get_target_block(fragment, self.targets) tb = get_target_block(fragment, self.targets)
if self.is_root: if self.is_root:
self.book.addTocEntry(text, tb) self.book.addTocEntry(ascii_text, tb)
sys.stdout.flush() sys.stdout.flush()
jb = JumpButton(tb) jb = JumpButton(tb)
self.book.append(jb) self.book.append(jb)
@ -566,7 +568,7 @@ class HTMLConverter(object):
else: else:
tb = conv.top tb = conv.top
if self.is_root: if self.is_root:
self.book.addTocEntry(text, tb) self.book.addTocEntry(ascii_text, tb)
jb = JumpButton(tb) jb = JumpButton(tb)
self.book.append(jb) self.book.append(jb)
cb = CharButton(jb, text=text) cb = CharButton(jb, text=text)