##// END OF EJS Templates
add posix_path filter...
MinRK -
Show More
@@ -55,6 +55,7 b' default_filters = {'
55 'highlight2html': filters.highlight2html,
55 'highlight2html': filters.highlight2html,
56 'highlight2latex': filters.highlight2latex,
56 'highlight2latex': filters.highlight2latex,
57 'ipython2python': filters.ipython2python,
57 'ipython2python': filters.ipython2python,
58 'posix_path': filters.posix_path,
58 'markdown2latex': filters.markdown2latex,
59 'markdown2latex': filters.markdown2latex,
59 'markdown2rst': filters.markdown2rst,
60 'markdown2rst': filters.markdown2rst,
60 'comment_lines': filters.comment_lines,
61 'comment_lines': filters.comment_lines,
@@ -66,7 +67,7 b' default_filters = {'
66 'ansi2latex': filters.ansi2latex,
67 'ansi2latex': filters.ansi2latex,
67 'strip_math_space': filters.strip_math_space,
68 'strip_math_space': filters.strip_math_space,
68 'wrap_text': filters.wrap_text,
69 'wrap_text': filters.wrap_text,
69 'escape_latex': filters.escape_latex
70 'escape_latex': filters.escape_latex,
70 }
71 }
71
72
72 #-----------------------------------------------------------------------------
73 #-----------------------------------------------------------------------------
@@ -16,6 +16,7 b' templates.'
16 # Imports
16 # Imports
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18
18
19 import os
19 import re
20 import re
20 import textwrap
21 import textwrap
21 from xml.etree import ElementTree
22 from xml.etree import ElementTree
@@ -36,6 +37,7 b' __all__ = ['
36 'comment_lines',
37 'comment_lines',
37 'get_lines',
38 'get_lines',
38 'ipython2python',
39 'ipython2python',
40 'posix_path',
39 ]
41 ]
40
42
41
43
@@ -169,3 +171,13 b' def ipython2python(code):'
169 """
171 """
170 shell = InteractiveShell.instance()
172 shell = InteractiveShell.instance()
171 return shell.input_transformer_manager.transform_cell(code)
173 return shell.input_transformer_manager.transform_cell(code)
174
175 def posix_path(path):
176 """Turn a path into posix-style path/to/etc
177
178 Mainly for use in latex on Windows,
179 where native Windows paths are not allowed.
180 """
181 if os.path.sep != '/':
182 return path.replace(os.path.sep, '/')
183 return path
@@ -17,7 +17,8 b' Module with tests for Strings'
17 from IPython.testing import decorators as dec
17 from IPython.testing import decorators as dec
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)
20 strip_files_prefix, get_lines, comment_lines, ipython2python, posix_path,
21 )
21
22
22
23
23 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
@@ -117,3 +118,10 b' class TestStrings(TestsBase):'
117 results = ipython2python(u'%%pylab\nprint("Hello-World")').replace("u'", "'")
118 results = ipython2python(u'%%pylab\nprint("Hello-World")').replace("u'", "'")
118 self.fuzzy_compare(results, u"get_ipython().run_cell_magic('pylab', '', 'print(\"Hello-World\")')",
119 self.fuzzy_compare(results, u"get_ipython().run_cell_magic('pylab', '', 'print(\"Hello-World\")')",
119 ignore_spaces=True, ignore_newlines=True)
120 ignore_spaces=True, ignore_newlines=True)
121
122 def test_posix_path(self):
123 path_list = ['foo', 'bar']
124 expected = '/'.join(path_list)
125 native = os.path.join(path_list)
126 filtered = posix_path(native)
127 self.assertEqual(filtered, expected)
General Comments 0
You need to be logged in to leave comments. Login now