diff --git a/IPython/nbconvert/filters/markdown.py b/IPython/nbconvert/filters/markdown.py index ffc9655..c880b0e 100755 --- a/IPython/nbconvert/filters/markdown.py +++ b/IPython/nbconvert/filters/markdown.py @@ -45,7 +45,7 @@ class NodeJSMissing(ConversionException): """Exception raised when node.js is missing.""" pass -def markdown2latex(source): +def markdown2latex(source, extra_args=None): """Convert a markdown string to LaTeX via pandoc. This function will raise an error if pandoc is not installed. @@ -61,7 +61,7 @@ def markdown2latex(source): out : string Output as returned by pandoc. """ - return pandoc(source, 'markdown', 'latex') + return pandoc(source, 'markdown', 'latex', extra_args=extra_args) @undoc @@ -155,9 +155,10 @@ def markdown2html_mistune(source): """Convert a markdown string to HTML using mistune""" return MarkdownWithMath(renderer=IPythonRenderer()).render(source) -def markdown2html_pandoc(source): +def markdown2html_pandoc(source, extra_args=None): """Convert a markdown string to HTML via pandoc""" - return pandoc(source, 'markdown', 'html', extra_args=['--mathjax']) + extra_args = extra_args or ['--mathjax'] + return pandoc(source, 'markdown', 'html', extra_args=extra_args) def _find_nodejs(): global _node @@ -188,7 +189,7 @@ def markdown2html_marked(source, encoding='utf-8'): # The mistune renderer is the default, because it's simple to depend on it markdown2html = markdown2html_mistune -def markdown2rst(source): +def markdown2rst(source, extra_args=None): """Convert a markdown string to ReST via pandoc. This function will raise an error if pandoc is not installed. @@ -204,7 +205,7 @@ def markdown2rst(source): out : string Output as returned by pandoc. """ - return pandoc(source, 'markdown', 'rst') + return pandoc(source, 'markdown', 'rst', extra_args=extra_args) def _verify_node(cmd): """Verify that the node command exists and is at least the minimum supported diff --git a/IPython/nbconvert/filters/tests/test_markdown.py b/IPython/nbconvert/filters/tests/test_markdown.py index 991caef..bf650db 100644 --- a/IPython/nbconvert/filters/tests/test_markdown.py +++ b/IPython/nbconvert/filters/tests/test_markdown.py @@ -11,6 +11,7 @@ from IPython.testing import decorators as dec from ...tests.base import TestsBase from ..markdown import markdown2latex, markdown2html, markdown2rst +from jinja2 import Environment class TestMarkdown(TestsBase): @@ -47,6 +48,26 @@ class TestMarkdown(TestsBase): for index, test in enumerate(self.tests): self._try_markdown(markdown2latex, test, self.tokens[index]) + @dec.onlyif_cmds_exist('pandoc') + def test_pandoc_extra_args(self): + # pass --no-wrap + s = '\n'.join([ + "#latex {{long_line | md2l(['--no-wrap'])}}", + "#rst {{long_line | md2r(['--columns', '5'])}}", + ]) + long_line = ' '.join(['long'] * 30) + env = Environment() + env.filters.update({ + 'md2l': markdown2latex, + 'md2r': markdown2rst, + }) + tpl = env.from_string(s) + rendered = tpl.render(long_line=long_line) + _, latex, rst = rendered.split('#') + + self.assertEqual(latex.strip(), 'latex %s' % long_line) + self.assertEqual(rst.strip(), 'rst %s' % long_line.replace(' ', '\n')) + def test_markdown2html(self): """markdown2html test""" for index, test in enumerate(self.tests):