##// END OF EJS Templates
allow passing extra args to pandoc filters...
MinRK -
Show More
@@ -45,7 +45,7 b' class NodeJSMissing(ConversionException):'
45 """Exception raised when node.js is missing."""
45 """Exception raised when node.js is missing."""
46 pass
46 pass
47
47
48 def markdown2latex(source):
48 def markdown2latex(source, extra_args=None):
49 """Convert a markdown string to LaTeX via pandoc.
49 """Convert a markdown string to LaTeX via pandoc.
50
50
51 This function will raise an error if pandoc is not installed.
51 This function will raise an error if pandoc is not installed.
@@ -61,7 +61,7 b' def markdown2latex(source):'
61 out : string
61 out : string
62 Output as returned by pandoc.
62 Output as returned by pandoc.
63 """
63 """
64 return pandoc(source, 'markdown', 'latex')
64 return pandoc(source, 'markdown', 'latex', extra_args=extra_args)
65
65
66
66
67 @undoc
67 @undoc
@@ -155,9 +155,10 b' def markdown2html_mistune(source):'
155 """Convert a markdown string to HTML using mistune"""
155 """Convert a markdown string to HTML using mistune"""
156 return MarkdownWithMath(renderer=IPythonRenderer()).render(source)
156 return MarkdownWithMath(renderer=IPythonRenderer()).render(source)
157
157
158 def markdown2html_pandoc(source):
158 def markdown2html_pandoc(source, extra_args=None):
159 """Convert a markdown string to HTML via pandoc"""
159 """Convert a markdown string to HTML via pandoc"""
160 return pandoc(source, 'markdown', 'html', extra_args=['--mathjax'])
160 extra_args = extra_args or ['--mathjax']
161 return pandoc(source, 'markdown', 'html', extra_args=extra_args)
161
162
162 def _find_nodejs():
163 def _find_nodejs():
163 global _node
164 global _node
@@ -188,7 +189,7 b" def markdown2html_marked(source, encoding='utf-8'):"
188 # The mistune renderer is the default, because it's simple to depend on it
189 # The mistune renderer is the default, because it's simple to depend on it
189 markdown2html = markdown2html_mistune
190 markdown2html = markdown2html_mistune
190
191
191 def markdown2rst(source):
192 def markdown2rst(source, extra_args=None):
192 """Convert a markdown string to ReST via pandoc.
193 """Convert a markdown string to ReST via pandoc.
193
194
194 This function will raise an error if pandoc is not installed.
195 This function will raise an error if pandoc is not installed.
@@ -204,7 +205,7 b' def markdown2rst(source):'
204 out : string
205 out : string
205 Output as returned by pandoc.
206 Output as returned by pandoc.
206 """
207 """
207 return pandoc(source, 'markdown', 'rst')
208 return pandoc(source, 'markdown', 'rst', extra_args=extra_args)
208
209
209 def _verify_node(cmd):
210 def _verify_node(cmd):
210 """Verify that the node command exists and is at least the minimum supported
211 """Verify that the node command exists and is at least the minimum supported
@@ -11,6 +11,7 b' from IPython.testing import decorators as dec'
11 from ...tests.base import TestsBase
11 from ...tests.base import TestsBase
12 from ..markdown import markdown2latex, markdown2html, markdown2rst
12 from ..markdown import markdown2latex, markdown2html, markdown2rst
13
13
14 from jinja2 import Environment
14
15
15 class TestMarkdown(TestsBase):
16 class TestMarkdown(TestsBase):
16
17
@@ -47,6 +48,26 b' class TestMarkdown(TestsBase):'
47 for index, test in enumerate(self.tests):
48 for index, test in enumerate(self.tests):
48 self._try_markdown(markdown2latex, test, self.tokens[index])
49 self._try_markdown(markdown2latex, test, self.tokens[index])
49
50
51 @dec.onlyif_cmds_exist('pandoc')
52 def test_pandoc_extra_args(self):
53 # pass --no-wrap
54 s = '\n'.join([
55 "#latex {{long_line | md2l(['--no-wrap'])}}",
56 "#rst {{long_line | md2r(['--columns', '5'])}}",
57 ])
58 long_line = ' '.join(['long'] * 30)
59 env = Environment()
60 env.filters.update({
61 'md2l': markdown2latex,
62 'md2r': markdown2rst,
63 })
64 tpl = env.from_string(s)
65 rendered = tpl.render(long_line=long_line)
66 _, latex, rst = rendered.split('#')
67
68 self.assertEqual(latex.strip(), 'latex %s' % long_line)
69 self.assertEqual(rst.strip(), 'rst %s' % long_line.replace(' ', '\n'))
70
50 def test_markdown2html(self):
71 def test_markdown2html(self):
51 """markdown2html test"""
72 """markdown2html test"""
52 for index, test in enumerate(self.tests):
73 for index, test in enumerate(self.tests):
General Comments 0
You need to be logged in to leave comments. Login now