Show More
@@ -12,6 +12,8 b' before_install:' | |||||
12 | - sudo rm -rf /dev/shm && sudo ln -s /run/shm /dev/shm |
|
12 | - sudo rm -rf /dev/shm && sudo ln -s /run/shm /dev/shm | |
13 | # Pierre Carrier's PPA for PhantomJS and CasperJS |
|
13 | # Pierre Carrier's PPA for PhantomJS and CasperJS | |
14 | - time sudo add-apt-repository -y ppa:pcarrier/ppa |
|
14 | - time sudo add-apt-repository -y ppa:pcarrier/ppa | |
|
15 | # Needed to get recent version of pandoc in ubntu 12.04 | |||
|
16 | - time sudo add-apt-repository -y ppa:marutter/c2d4u | |||
15 | - time sudo apt-get update |
|
17 | - time sudo apt-get update | |
16 | - time sudo apt-get install pandoc casperjs libzmq3-dev |
|
18 | - time sudo apt-get install pandoc casperjs libzmq3-dev | |
17 | # pin tornado < 4 for js tests while phantom is on super old webkit |
|
19 | # pin tornado < 4 for js tests while phantom is on super old webkit |
@@ -62,6 +62,7 b' default_filters = {' | |||||
62 | 'path2url': filters.path2url, |
|
62 | 'path2url': filters.path2url, | |
63 | 'add_prompts': filters.add_prompts, |
|
63 | 'add_prompts': filters.add_prompts, | |
64 | 'ascii_only': filters.ascii_only, |
|
64 | 'ascii_only': filters.ascii_only, | |
|
65 | 'prevent_list_blocks': filters.prevent_list_blocks, | |||
65 | } |
|
66 | } | |
66 |
|
67 | |||
67 | #----------------------------------------------------------------------------- |
|
68 | #----------------------------------------------------------------------------- |
@@ -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, extra_args=None): |
|
48 | def markdown2latex(source, markup='markdown', 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. | |
@@ -55,13 +55,17 b' def markdown2latex(source, extra_args=None):' | |||||
55 | ---------- |
|
55 | ---------- | |
56 | source : string |
|
56 | source : string | |
57 | Input string, assumed to be valid markdown. |
|
57 | Input string, assumed to be valid markdown. | |
|
58 | markup : string | |||
|
59 | Markup used by pandoc's reader | |||
|
60 | default : pandoc extended markdown | |||
|
61 | (see http://johnmacfarlane.net/pandoc/README.html#pandocs-markdown) | |||
58 |
|
62 | |||
59 | Returns |
|
63 | Returns | |
60 | ------- |
|
64 | ------- | |
61 | out : string |
|
65 | out : string | |
62 | Output as returned by pandoc. |
|
66 | Output as returned by pandoc. | |
63 | """ |
|
67 | """ | |
64 |
return pandoc(source, |
|
68 | return pandoc(source, markup, 'latex', extra_args=extra_args) | |
65 |
|
69 | |||
66 |
|
70 | |||
67 | @undoc |
|
71 | @undoc |
@@ -45,6 +45,7 b' __all__ = [' | |||||
45 | 'path2url', |
|
45 | 'path2url', | |
46 | 'add_prompts', |
|
46 | 'add_prompts', | |
47 | 'ascii_only', |
|
47 | 'ascii_only', | |
|
48 | 'prevent_list_blocks', | |||
48 | ] |
|
49 | ] | |
49 |
|
50 | |||
50 |
|
51 | |||
@@ -218,4 +219,14 b' def path2url(path):' | |||||
218 | def ascii_only(s): |
|
219 | def ascii_only(s): | |
219 | """ensure a string is ascii""" |
|
220 | """ensure a string is ascii""" | |
220 | s = py3compat.cast_unicode(s) |
|
221 | s = py3compat.cast_unicode(s) | |
221 | return s.encode('ascii', 'replace').decode('ascii') No newline at end of file |
|
222 | return s.encode('ascii', 'replace').decode('ascii') | |
|
223 | ||||
|
224 | def prevent_list_blocks(s): | |||
|
225 | """ | |||
|
226 | Prevent presence of enumerate or itemize blocks in latex headings cells | |||
|
227 | """ | |||
|
228 | out = re.sub('(^\s*\d*)\.', '\\1\.', s) | |||
|
229 | out = re.sub('(^\s*)\-', '\\1\-', out) | |||
|
230 | out = re.sub('(^\s*)\+', '\\1\+', out) | |||
|
231 | out = re.sub('(^\s*)\*', '\\1\*', out) | |||
|
232 | return out |
@@ -49,10 +49,24 b' class TestMarkdown(TestsBase):' | |||||
49 | self._try_markdown(markdown2latex, test, self.tokens[index]) |
|
49 | self._try_markdown(markdown2latex, test, self.tokens[index]) | |
50 |
|
50 | |||
51 | @dec.onlyif_cmds_exist('pandoc') |
|
51 | @dec.onlyif_cmds_exist('pandoc') | |
|
52 | def test_markdown2latex_markup(self): | |||
|
53 | """markdown2latex with markup kwarg test""" | |||
|
54 | # This string should be passed through unaltered with pandoc's | |||
|
55 | # markdown_strict reader | |||
|
56 | s = '1) arabic number with parenthesis' | |||
|
57 | self.assertEqual(markdown2latex(s, markup='markdown_strict'), s) | |||
|
58 | # This string should be passed through unaltered with pandoc's | |||
|
59 | # markdown_strict+tex_math_dollars reader | |||
|
60 | s = '$\\alpha$ latex math' | |||
|
61 | self.assertEqual( | |||
|
62 | markdown2latex(s, markup='markdown_strict+tex_math_dollars'), | |||
|
63 | s) | |||
|
64 | ||||
|
65 | @dec.onlyif_cmds_exist('pandoc') | |||
52 | def test_pandoc_extra_args(self): |
|
66 | def test_pandoc_extra_args(self): | |
53 | # pass --no-wrap |
|
67 | # pass --no-wrap | |
54 | s = '\n'.join([ |
|
68 | s = '\n'.join([ | |
55 | "#latex {{long_line | md2l(['--no-wrap'])}}", |
|
69 | "#latex {{long_line | md2l('markdown', ['--no-wrap'])}}", | |
56 | "#rst {{long_line | md2r(['--columns', '5'])}}", |
|
70 | "#rst {{long_line | md2r(['--columns', '5'])}}", | |
57 | ]) |
|
71 | ]) | |
58 | long_line = ' '.join(['long'] * 30) |
|
72 | long_line = ' '.join(['long'] * 30) | |
@@ -64,7 +78,7 b' class TestMarkdown(TestsBase):' | |||||
64 | tpl = env.from_string(s) |
|
78 | tpl = env.from_string(s) | |
65 | rendered = tpl.render(long_line=long_line) |
|
79 | rendered = tpl.render(long_line=long_line) | |
66 | _, latex, rst = rendered.split('#') |
|
80 | _, latex, rst = rendered.split('#') | |
67 |
|
81 | |||
68 | self.assertEqual(latex.strip(), 'latex %s' % long_line) |
|
82 | self.assertEqual(latex.strip(), 'latex %s' % long_line) | |
69 | self.assertEqual(rst.strip(), 'rst %s' % long_line.replace(' ', '\n')) |
|
83 | self.assertEqual(rst.strip(), 'rst %s' % long_line.replace(' ', '\n')) | |
70 |
|
84 |
@@ -18,7 +18,7 b' import os' | |||||
18 | from ...tests.base import TestsBase |
|
18 | from ...tests.base import TestsBase | |
19 | from ..strings import (wrap_text, html2text, add_anchor, strip_dollars, |
|
19 | from ..strings import (wrap_text, html2text, add_anchor, strip_dollars, | |
20 | strip_files_prefix, get_lines, comment_lines, ipython2python, posix_path, |
|
20 | strip_files_prefix, get_lines, comment_lines, ipython2python, posix_path, | |
21 | add_prompts |
|
21 | add_prompts, prevent_list_blocks | |
22 | ) |
|
22 | ) | |
23 |
|
23 | |||
24 |
|
24 | |||
@@ -151,3 +151,15 b' class TestStrings(TestsBase):' | |||||
151 | text1 = """for i in range(10):\n i += 1\n print i""" |
|
151 | text1 = """for i in range(10):\n i += 1\n print i""" | |
152 | text2 = """>>> for i in range(10):\n... i += 1\n... print i""" |
|
152 | text2 = """>>> for i in range(10):\n... i += 1\n... print i""" | |
153 | self.assertEqual(text2, add_prompts(text1)) |
|
153 | self.assertEqual(text2, add_prompts(text1)) | |
|
154 | ||||
|
155 | def test_prevent_list_blocks(self): | |||
|
156 | """prevent_list_blocks test""" | |||
|
157 | tests = [ | |||
|
158 | ('1. arabic point', '1\\. arabic point'), | |||
|
159 | ('* bullet asterisk', '\\* bullet asterisk'), | |||
|
160 | ('+ bullet Plus Sign', '\\+ bullet Plus Sign'), | |||
|
161 | ('- bullet Hyphen-Minus', '\\- bullet Hyphen-Minus'), | |||
|
162 | (' 1. spaces + arabic point', ' 1\\. spaces + arabic point'), | |||
|
163 | ] | |||
|
164 | for test in tests: | |||
|
165 | self.assertEqual(prevent_list_blocks(test[0]), test[1]) |
@@ -201,7 +201,8 b' This template does not define a docclass, the inheriting class must define this.' | |||||
201 | ((* elif cell.level == 6 -*)) |
|
201 | ((* elif cell.level == 6 -*)) | |
202 | ((* block h6 -*))\\*\textit((* endblock h6 -*)) |
|
202 | ((* block h6 -*))\\*\textit((* endblock h6 -*)) | |
203 | ((*- endif -*)) |
|
203 | ((*- endif -*)) | |
204 | {((( cell.source | replace('\n', ' ') | citation2latex | strip_files_prefix | markdown2latex )))} |
|
204 | {((( cell.source | replace('\n', ' ') | citation2latex | strip_files_prefix | prevent_list_blocks | markdown2latex(markup='markdown_strict+tex_math_dollars') )))} | |
|
205 | ||||
205 |
|
206 | |||
206 | ((* endblock headingcell *)) |
|
207 | ((* endblock headingcell *)) | |
207 |
|
208 |
General Comments 0
You need to be logged in to leave comments.
Login now