diff --git a/.bzrignore b/.bzrignore
index 17d232238f..e2d1636ddd 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -28,3 +28,4 @@ nbproject/
*.userprefs
.project
.pydevproject
+.settings/
diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py
index d61f4369e6..d57389445c 100644
--- a/src/calibre/ebooks/fb2/fb2ml.py
+++ b/src/calibre/ebooks/fb2/fb2ml.py
@@ -86,10 +86,12 @@ class FB2MLizer(object):
output.append(self.fb2_footer())
output = ''.join(output).replace(u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk', self.get_toc())
output = self.clean_text(output)
+ if self.opts.sectionize_chapters:
+ output = self.sectionize_chapters(output)
return u'\n%s' % etree.tostring(etree.fromstring(output), encoding=unicode, pretty_print=True)
def clean_text(self, text):
- text = re.sub('
[ ]*
', '', text)
+ text = re.sub('\s*
', '', text)
return text
@@ -149,6 +151,11 @@ class FB2MLizer(object):
self.oeb.warn('Ignoring toc item: %s not found in document.' % item)
return ''.join(toc)
+ def sectionize_chapters(self, text):
+ text = re.sub(r'(?imsu)(?P)\s*(?P()*\s*.+?\s*(
)*)', lambda mo: '%s%s' % (mo.group('anchor'), mo.group('strong')), text)
+ text = re.sub(r'(?imsu)\s*(?P)\s*
\s*(?P()*\s*.+?\s*(
)*)', lambda mo: '%s%s' % (mo.group('anchor'), mo.group('strong')), text)
+ return text
+
def get_text(self):
text = []
for item in self.oeb_book.spine:
diff --git a/src/calibre/ebooks/fb2/output.py b/src/calibre/ebooks/fb2/output.py
index 2bb49318af..d0125afe89 100644
--- a/src/calibre/ebooks/fb2/output.py
+++ b/src/calibre/ebooks/fb2/output.py
@@ -19,6 +19,12 @@ class FB2Output(OutputFormatPlugin):
OptionRecommendation(name='inline_toc',
recommended_value=False, level=OptionRecommendation.LOW,
help=_('Add Table of Contents to beginning of the book.')),
+ OptionRecommendation(name='sectionize_chapters',
+ recommended_value=False, level=OptionRecommendation.LOW,
+ help=_('Try to turn chapters into individual sections. ' \
+ 'WARNING: ' \
+ 'This option is experimental. It can cause conversion ' \
+ 'to fail. It can also produce unexpected output.')),
])
def convert(self, oeb_book, output_path, input_plugin, opts, log):
diff --git a/src/calibre/gui2/convert/fb2_output.py b/src/calibre/gui2/convert/fb2_output.py
index 55c708c2a4..145b14f8c9 100644
--- a/src/calibre/gui2/convert/fb2_output.py
+++ b/src/calibre/gui2/convert/fb2_output.py
@@ -16,6 +16,6 @@ class PluginWidget(Widget, Ui_Form):
COMMIT_NAME = 'fb2_output'
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
- Widget.__init__(self, parent, ['inline_toc'])
+ Widget.__init__(self, parent, ['inline_toc', 'sectionize_chapters'])
self.db, self.book_id = db, book_id
self.initialize_options(get_option, get_help, db, book_id)
diff --git a/src/calibre/gui2/convert/fb2_output.ui b/src/calibre/gui2/convert/fb2_output.ui
index 007af454c4..a43a8b72ea 100644
--- a/src/calibre/gui2/convert/fb2_output.ui
+++ b/src/calibre/gui2/convert/fb2_output.ui
@@ -14,7 +14,7 @@
Form
- -
+
-
Qt::Vertical
@@ -34,6 +34,13 @@
+ -
+
+
+ Sectionize Chapters (Use with care!)
+
+
+