##// END OF EJS Templates
Merge pull request #4505 from mrmagooey/nbconvert-latex-markdown-images2...
MinRK -
r13871:52b12218 merge
parent child Browse files
Show More
@@ -60,4 +60,4 b' def escape_latex(text):'
60 60 text = pattern.sub(replacement, text)
61 61
62 62 return text
63
63
@@ -122,19 +122,22 b' def strip_dollars(text):'
122 122 return text.strip('$')
123 123
124 124
125 files_url_pattern = re.compile(r'(src|href)\=([\'"]?)files/')
125 files_url_pattern = re.compile(r'(src|href)\=([\'"]?)/?files/')
126 markdown_url_pattern = re.compile(r'(!?)\[(?P<caption>.*?)\]\(/?files/(?P<location>.*?)\)')
126 127
127 128 def strip_files_prefix(text):
128 129 """
129 Fix all fake URLs that start with `files/`,
130 stripping out the `files/` prefix.
130 Fix all fake URLs that start with `files/`, stripping out the `files/` prefix.
131 Applies to both urls (for html) and relative paths (for markdown paths).
131 132
132 133 Parameters
133 134 ----------
134 135 text : str
135 136 Text in which to replace 'src="files/real...' with 'src="real...'
136 137 """
137 return files_url_pattern.sub(r"\1=\2", text)
138 cleaned_text = files_url_pattern.sub(r"\1=\2", text)
139 cleaned_text = markdown_url_pattern.sub(r'\1[\2](\3)', cleaned_text)
140 return cleaned_text
138 141
139 142
140 143 def comment_lines(text, prefix='# '):
@@ -41,5 +41,3 b' class TestLatex(TestsBase):'
41 41 def _try_escape_latex(self, test, result):
42 42 """Try to remove latex from string"""
43 43 self.assertEqual(escape_latex(test), result)
44
45
@@ -87,7 +87,20 b' class TestStrings(TestsBase):'
87 87 ('/files', '/files'),
88 88 ('test="/files"', 'test="/files"'),
89 89 ('My files are in `files/`', 'My files are in `files/`'),
90 ('<a href="files/test.html">files/test.html</a>', '<a href="test.html">files/test.html</a>')]
90 ('<a href="files/test.html">files/test.html</a>', '<a href="test.html">files/test.html</a>'),
91 ('<a href="/files/test.html">files/test.html</a>', '<a href="test.html">files/test.html</a>'),
92 ("<a href='files/test.html'>files/test.html</a>", "<a href='test.html'>files/test.html</a>"),
93 ('<img src="files/url/location.gif">', '<img src="url/location.gif">'),
94 ('<img src="/files/url/location.gif">', '<img src="url/location.gif">'),
95 ('hello![caption]', 'hello![caption]'),
96 ('hello![caption](/url/location.gif)', 'hello![caption](/url/location.gif)'),
97 ('hello![caption](url/location.gif)', 'hello![caption](url/location.gif)'),
98 ('hello![caption](url/location.gif)', 'hello![caption](url/location.gif)'),
99 ('hello![caption](files/url/location.gif)', 'hello![caption](url/location.gif)'),
100 ('hello![caption](/files/url/location.gif)', 'hello![caption](url/location.gif)'),
101 ('hello [text](/files/url/location.gif)', 'hello [text](url/location.gif)'),
102 ('hello [text space](files/url/location.gif)', 'hello [text space](url/location.gif)'),
103 ]
91 104 for test in tests:
92 105 self._try_files_prefix(test[0], test[1])
93 106
@@ -202,7 +202,7 b' This template does not define a docclass, the inheriting class must define this.'
202 202 ((* elif cell.level == 6 -*))
203 203 ((* block h6 -*))\\*\textit((* endblock h6 -*))
204 204 ((*- endif -*))
205 {((( cell.source | replace('\n', ' ') | citation2latex | markdown2latex )))}
205 {((( cell.source | replace('\n', ' ') | citation2latex | strip_files_prefix | markdown2latex )))}
206 206
207 207 ((* endblock headingcell *))
208 208
@@ -215,7 +215,7 b' This template does not define a docclass, the inheriting class must define this.'
215 215
216 216 % Render markdown
217 217 ((* block markdowncell scoped *))
218 ((( cell.source | citation2latex | markdown2latex )))
218 ((( cell.source | citation2latex | strip_files_prefix | markdown2latex )))
219 219 ((* endblock markdowncell *))
220 220
221 221 % Don't display unknown types
General Comments 0
You need to be logged in to leave comments. Login now