mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix FB2 output.
This commit is contained in:
parent
bb6ef9ab4d
commit
62317ca8cf
@ -30,6 +30,7 @@ TAG_MAP = {
|
|||||||
'i' : 'emphasis',
|
'i' : 'emphasis',
|
||||||
'p' : 'p',
|
'p' : 'p',
|
||||||
'li' : 'p',
|
'li' : 'p',
|
||||||
|
'br' : 'empty-line',
|
||||||
}
|
}
|
||||||
|
|
||||||
TAG_SPACE = [
|
TAG_SPACE = [
|
||||||
@ -74,6 +75,7 @@ class FB2MLizer(object):
|
|||||||
output.append(self.fb2mlize_images())
|
output.append(self.fb2mlize_images())
|
||||||
output.append(self.fb2_footer())
|
output.append(self.fb2_footer())
|
||||||
output = ''.join(output).replace(u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk', self.get_toc())
|
output = ''.join(output).replace(u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk', self.get_toc())
|
||||||
|
return output
|
||||||
return u'<?xml version="1.0" encoding="UTF-8"?>\n%s' % etree.tostring(etree.fromstring(output), encoding=unicode, pretty_print=True)
|
return u'<?xml version="1.0" encoding="UTF-8"?>\n%s' % etree.tostring(etree.fromstring(output), encoding=unicode, pretty_print=True)
|
||||||
|
|
||||||
def fb2_header(self):
|
def fb2_header(self):
|
||||||
@ -112,7 +114,7 @@ class FB2MLizer(object):
|
|||||||
item = self.oeb_book.manifest.hrefs[href]
|
item = self.oeb_book.manifest.hrefs[href]
|
||||||
if item.spine_position is None:
|
if item.spine_position is None:
|
||||||
stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile)
|
stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile)
|
||||||
output += self.dump_text(item.data.find(XHTML('body')), stylizer, item)
|
output += ''.join(self.dump_text(item.data.find(XHTML('body')), stylizer, item))
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_toc(self):
|
def get_toc(self):
|
||||||
@ -151,7 +153,7 @@ class FB2MLizer(object):
|
|||||||
if aid not in self.link_hrefs.keys():
|
if aid not in self.link_hrefs.keys():
|
||||||
self.link_hrefs[aid] = 'calibre_link-%s' % len(self.link_hrefs.keys())
|
self.link_hrefs[aid] = 'calibre_link-%s' % len(self.link_hrefs.keys())
|
||||||
aid = self.link_hrefs[aid]
|
aid = self.link_hrefs[aid]
|
||||||
return '<v id="%s"></v>' % aid
|
return '<a id="%s" />' % aid
|
||||||
|
|
||||||
def fb2mlize_images(self):
|
def fb2mlize_images(self):
|
||||||
images = [u'']
|
images = [u'']
|
||||||
@ -204,6 +206,7 @@ class FB2MLizer(object):
|
|||||||
href = elem.get('href')
|
href = elem.get('href')
|
||||||
if href:
|
if href:
|
||||||
href = prepare_string_for_xml(page.abshref(href))
|
href = prepare_string_for_xml(page.abshref(href))
|
||||||
|
href = href.replace('"', '"')
|
||||||
if '://' in href:
|
if '://' in href:
|
||||||
fb2_text.append('<a xlink:href="%s">' % href)
|
fb2_text.append('<a xlink:href="%s">' % href)
|
||||||
else:
|
else:
|
||||||
@ -240,7 +243,10 @@ class FB2MLizer(object):
|
|||||||
fb2_text.append(' ')
|
fb2_text.append(' ')
|
||||||
|
|
||||||
if hasattr(elem, 'text') and elem.text != None:
|
if hasattr(elem, 'text') and elem.text != None:
|
||||||
fb2_text.append(prepare_string_for_xml(elem.text))
|
if 'p' not in tag_stack:
|
||||||
|
fb2_text.append('<p>%s</p>' % prepare_string_for_xml(elem.text))
|
||||||
|
else:
|
||||||
|
fb2_text.append(prepare_string_for_xml(elem.text))
|
||||||
|
|
||||||
for item in elem:
|
for item in elem:
|
||||||
fb2_text += self.dump_text(item, stylizer, page, tag_stack)
|
fb2_text += self.dump_text(item, stylizer, page, tag_stack)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user