FB2 Input: Add support for FB2 books that use the FictionBook 2.1 XML schema. Fixes #1401915 [can't read fb2, saved from samlib.ru](https://bugs.launchpad.net/calibre/+bug/1401915)

This commit is contained in:
Kovid Goyal 2014-12-14 10:52:46 +05:30
parent 74b391f1c7
commit 610f2e32cb
2 changed files with 6 additions and 1 deletions

View File

@ -1,4 +1,4 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0"> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="__FB_NS__">
<!-- <!--
######################################################################### #########################################################################
# # # #

View File

@ -58,6 +58,10 @@ class FB2Input(InputFormatPlugin):
parser=RECOVER_PARSER) parser=RECOVER_PARSER)
if doc is None: if doc is None:
raise ValueError('The FB2 file is not valid XML') raise ValueError('The FB2 file is not valid XML')
try:
fb_ns = doc.nsmap[doc.prefix]
except Exception:
fb_ns = 'http://www.gribuser.ru/xml/fictionbook/2.0'
stylesheets = doc.xpath('//*[local-name() = "stylesheet" and @type="text/css"]') stylesheets = doc.xpath('//*[local-name() = "stylesheet" and @type="text/css"]')
css = '' css = ''
for s in stylesheets: for s in stylesheets:
@ -78,6 +82,7 @@ class FB2Input(InputFormatPlugin):
self.extract_embedded_content(doc) self.extract_embedded_content(doc)
log.debug('Converting XML to HTML...') log.debug('Converting XML to HTML...')
ss = open(P('templates/fb2.xsl'), 'rb').read() ss = open(P('templates/fb2.xsl'), 'rb').read()
ss = ss.replace("__FB_NS__", fb_ns)
if options.no_inline_fb2_toc: if options.no_inline_fb2_toc:
log('Disabling generation of inline FB2 TOC') log('Disabling generation of inline FB2 TOC')
ss = re.compile(r'<!-- BUILD TOC -->.*<!-- END BUILD TOC -->', ss = re.compile(r'<!-- BUILD TOC -->.*<!-- END BUILD TOC -->',