Show More
@@ -45,7 +45,7 b' class NodeJSMissing(ConversionException):' | |||
|
45 | 45 | """Exception raised when node.js is missing.""" |
|
46 | 46 | pass |
|
47 | 47 | |
|
48 | def markdown2latex(source): | |
|
48 | def markdown2latex(source, extra_args=None): | |
|
49 | 49 | """Convert a markdown string to LaTeX via pandoc. |
|
50 | 50 | |
|
51 | 51 | This function will raise an error if pandoc is not installed. |
@@ -61,7 +61,7 b' def markdown2latex(source):' | |||
|
61 | 61 | out : string |
|
62 | 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 | 67 | @undoc |
@@ -155,9 +155,10 b' def markdown2html_mistune(source):' | |||
|
155 | 155 | """Convert a markdown string to HTML using mistune""" |
|
156 | 156 | return MarkdownWithMath(renderer=IPythonRenderer()).render(source) |
|
157 | 157 | |
|
158 | def markdown2html_pandoc(source): | |
|
158 | def markdown2html_pandoc(source, extra_args=None): | |
|
159 | 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 | 163 | def _find_nodejs(): |
|
163 | 164 | global _node |
@@ -188,7 +189,7 b" def markdown2html_marked(source, encoding='utf-8'):" | |||
|
188 | 189 | # The mistune renderer is the default, because it's simple to depend on it |
|
189 | 190 | markdown2html = markdown2html_mistune |
|
190 | 191 | |
|
191 | def markdown2rst(source): | |
|
192 | def markdown2rst(source, extra_args=None): | |
|
192 | 193 | """Convert a markdown string to ReST via pandoc. |
|
193 | 194 | |
|
194 | 195 | This function will raise an error if pandoc is not installed. |
@@ -204,7 +205,7 b' def markdown2rst(source):' | |||
|
204 | 205 | out : string |
|
205 | 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 | 210 | def _verify_node(cmd): |
|
210 | 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 | 11 | from ...tests.base import TestsBase |
|
12 | 12 | from ..markdown import markdown2latex, markdown2html, markdown2rst |
|
13 | 13 | |
|
14 | from jinja2 import Environment | |
|
14 | 15 | |
|
15 | 16 | class TestMarkdown(TestsBase): |
|
16 | 17 | |
@@ -47,6 +48,26 b' class TestMarkdown(TestsBase):' | |||
|
47 | 48 | for index, test in enumerate(self.tests): |
|
48 | 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 | 71 | def test_markdown2html(self): |
|
51 | 72 | """markdown2html test""" |
|
52 | 73 | for index, test in enumerate(self.tests): |
General Comments 0
You need to be logged in to leave comments.
Login now