diff --git a/src/calibre/ebooks/markdown/mdx_toc.py b/src/calibre/ebooks/markdown/mdx_toc.py
index a8c1db267d..15fd5061a0 100644
--- a/src/calibre/ebooks/markdown/mdx_toc.py
+++ b/src/calibre/ebooks/markdown/mdx_toc.py
@@ -44,13 +44,13 @@ class TocExtension (markdown.Extension):
replaces first string occurence of "///Table of Contents Goes Here///"
"""
- def __init__ (self) :
+ def __init__ (self, configs={}) :
#maybe add these as parameters to the class init?
self.TOC_INCLUDE_MARKER = "///Table of Contents///"
self.TOC_TITLE = "Table Of Contents"
self.auto_toc_heading_type=2
self.toc_heading_type=3
-
+ self.configs = configs
def extendMarkdown(self, md, md_globals) :
# Just insert in the end
@@ -148,16 +148,22 @@ class TocPostprocessor (markdown.Postprocessor):
def run(self, doc):
tocPlaceholder = self.toc.findTocPlaceholder(doc)
- tocDiv = self.toc.createTocDiv(doc)
- if tocDiv:
- if tocPlaceholder :
- # Replace "magic" pattern with toc
- tocPlaceholder.parent.replaceChild(tocPlaceholder, tocDiv)
- else :
- # Dump at the end of the DOM
- # Probably want to use CSS to position div
- doc.documentElement.appendChild(tocDiv)
+ if self.toc.configs.get("disable_toc", False):
+ if tocPlaceholder:
+ tocPlaceholder.parent.replaceChild(tocPlaceholder, "")
+ else:
+
+ tocDiv = self.toc.createTocDiv(doc)
+
+ if tocDiv:
+ if tocPlaceholder :
+ # Replace "magic" pattern with toc
+ tocPlaceholder.parent.replaceChild(tocPlaceholder, tocDiv)
+ else :
+ # Dump at the end of the DOM
+ # Probably want to use CSS to position div
+ doc.documentElement.appendChild(tocDiv)
-def makeExtension(configs=None) :
- return TocExtension()
+def makeExtension(configs={}):
+ return TocExtension(configs=configs)
diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py
index c57dfc3706..96140ce195 100644
--- a/src/calibre/ebooks/oeb/base.py
+++ b/src/calibre/ebooks/oeb/base.py
@@ -960,7 +960,7 @@ class Manifest(object):
else:
title = _('Unknown')
- return self._parse_xhtml(convert_markdown(data, title))
+ return self._parse_xhtml(convert_markdown(data, title=title))
def _parse_css(self, data):
diff --git a/src/calibre/ebooks/txt/input.py b/src/calibre/ebooks/txt/input.py
index 278efd4847..9b1d80be3f 100644
--- a/src/calibre/ebooks/txt/input.py
+++ b/src/calibre/ebooks/txt/input.py
@@ -31,6 +31,8 @@ class TXTInput(InputFormatPlugin):
OptionRecommendation(name='markdown', recommended_value=False,
help=_('Run the text input through the markdown pre-processor. To '
'learn more about markdown see')+' http://daringfireball.net/projects/markdown/'),
+ OptionRecommendation(name="markdown_disable_toc", recommended_value=False,
+ help=_('Do not insert a Table of Contents into the output text.')),
])
def convert(self, stream, options, file_ext, log,
@@ -50,7 +52,7 @@ class TXTInput(InputFormatPlugin):
if options.markdown:
log.debug('Running text though markdown conversion...')
try:
- html = convert_markdown(txt)
+ html = convert_markdown(txt, disable_toc=options.markdown_disable_toc)
except RuntimeError:
raise ValueError('This txt file has malformed markup, it cannot be'
'converted by calibre. See http://daringfireball.net/projects/markdown/syntax')
diff --git a/src/calibre/ebooks/txt/processor.py b/src/calibre/ebooks/txt/processor.py
index 9d0e1283c1..06276a4bbc 100644
--- a/src/calibre/ebooks/txt/processor.py
+++ b/src/calibre/ebooks/txt/processor.py
@@ -39,10 +39,11 @@ def convert_basic(txt, title=''):
return HTML_TEMPLATE % (title, '\n'.join(lines))
-def convert_markdown(txt, title=''):
+def convert_markdown(txt, title='', disable_toc=False):
md = markdown.Markdown(
- extensions=['footnotes', 'tables', 'toc'],
- safe_mode=False,)
+ extensions=['footnotes', 'tables', 'toc'],
+ extension_configs={"toc": {"disable_toc": disable_toc}},
+ safe_mode=False)
return HTML_TEMPLATE % (title, md.convert(txt))
def separate_paragraphs_single_line(txt):
diff --git a/src/calibre/gui2/convert/txt_input.py b/src/calibre/gui2/convert/txt_input.py
index 505a916f81..7fe6f6274c 100644
--- a/src/calibre/gui2/convert/txt_input.py
+++ b/src/calibre/gui2/convert/txt_input.py
@@ -14,6 +14,6 @@ class PluginWidget(Widget, Ui_Form):
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'txt_input',
- ['single_line_paras', 'print_formatted_paras', 'markdown'])
+ ['single_line_paras', 'print_formatted_paras', 'markdown', 'markdown_disable_toc'])
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/txt_input.ui b/src/calibre/gui2/convert/txt_input.ui
index 94cc1ad25f..9fde157d33 100644
--- a/src/calibre/gui2/convert/txt_input.ui
+++ b/src/calibre/gui2/convert/txt_input.ui
@@ -14,19 +14,6 @@
Form
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 213
-
-
-
-
-
@@ -34,6 +21,13 @@
+ -
+
+
+ Assume print formatting
+
+
+
-
@@ -51,15 +45,45 @@
- -
-
+
-
+
- Assume print formatting
+ Do not insert Table of Contents into output text when using markdown
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 213
+
+
+
+
-
+
+
+ opt_markdown
+ toggled(bool)
+ opt_markdown_disable_toc
+ setEnabled(bool)
+
+
+ 76
+ 80
+
+
+ 418
+ 105
+
+
+
+