FB2 Input: Implement option to disable generation of Table of Contents at start of book. Fixes #2908 (FIX: fb2 Input plugin auto created the ToC)

This commit is contained in:
Kovid Goyal 2009-07-26 14:28:49 -06:00
parent 15e369a806
commit 51a6ad79ae
4 changed files with 79 additions and 2 deletions

View File

@ -60,6 +60,7 @@
<xsl:apply-templates select="fb:body" mode="toc"/>
</ul>
<hr/>
<!-- END BUILD TOC -->
<!-- BUILD BOOK -->
<xsl:for-each select="fb:body">
<xsl:if test="position()!=1">

View File

@ -4,7 +4,7 @@ __copyright__ = '2008, Anatoly Shipitsin <norguhtar at gmail.com>'
"""
Convert .fb2 files to .lrf
"""
import os
import os, re
from base64 import b64decode
from lxml import etree
@ -26,6 +26,16 @@ class FB2Input(InputFormatPlugin):
('level3_toc', '//h:h3', OptionRecommendation.MED),
])
options = set([
OptionRecommendation(name='no_inline_fb2_toc',
recommended_value=False, level=OptionRecommendation.LOW,
help=_('Do not insert a Table of Contents at the beginning of the book.'
)
),
])
def convert(self, stream, options, file_ext, log,
accelerators):
from calibre.resources import fb2_xsl
@ -39,7 +49,13 @@ class FB2Input(InputFormatPlugin):
doc = etree.parse(stream, parser)
self.extract_embedded_content(doc)
log.debug('Converting XML to HTML...')
styledoc = etree.fromstring(fb2_xsl)
ss = fb2_xsl
if options.no_inline_fb2_toc:
log('Disabling generation of inline FB2 TOC')
ss = re.compile(r'<!-- BUILD TOC -->.*<!-- END BUILD TOC -->',
re.DOTALL).sub('', ss)
styledoc = etree.fromstring(ss)
transform = etree.XSLT(styledoc)
result = transform(doc)

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
__license__ = 'GPL 3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
from calibre.gui2.convert.fb2_input_ui import Ui_Form
from calibre.gui2.convert import Widget
class PluginWidget(Widget, Ui_Form):
TITLE = _('FB2 Input')
HELP = _('Options specific to')+' FB2 '+_('input')
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'fb2_input',
['no_inline_fb2_toc'])
self.db, self.book_id = db, book_id
self.initialize_options(get_option, get_help, db, book_id)

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>213</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="opt_no_inline_fb2_toc">
<property name="text">
<string>Do not insert a &amp;Table of Contents at the beginning of the book.</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>