mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
lrs2lrf: Handle missing style labels gracefully
This commit is contained in:
parent
2c5d951139
commit
a80d705049
@ -167,7 +167,7 @@ class LrsParser(object):
|
||||
settings = self.attrs_to_dict(tag, map[tag.name][1]+['objid', 'objlabel'])
|
||||
for a in ('pagestyle', 'blockstyle', 'textstyle'):
|
||||
label = tag.get(a, False)
|
||||
if label:
|
||||
if label and label in self._style_labels:
|
||||
_obj = self.parsed_objects[label] if \
|
||||
self.parsed_objects.has_key(label) else \
|
||||
self._style_labels[label]
|
||||
|
@ -5,7 +5,19 @@ meaning as possible.
|
||||
|
||||
from calibre.ebooks.unidecode.unidecoder import Unidecoder
|
||||
from calibre import sanitize_file_name
|
||||
from calibre.constants import preferred_encoding
|
||||
udc = Unidecoder()
|
||||
|
||||
def ascii_text(orig):
|
||||
try:
|
||||
ascii = udc.decode(orig)
|
||||
except:
|
||||
if isinstance(orig, unicode):
|
||||
ascii = orig.encode('ascii', 'replace')
|
||||
ascii = orig.decode(preferred_encoding,
|
||||
'replace').encode('ascii', 'replace')
|
||||
return ascii
|
||||
|
||||
|
||||
def ascii_filename(orig):
|
||||
return sanitize_file_name(udc.decode(orig).replace('?', '_'))
|
||||
return sanitize_file_name(ascii_text(orig).replace('?', '_'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user