Show More
@@ -60,4 +60,4 b' def escape_latex(text):' | |||||
60 | text = pattern.sub(replacement, text) |
|
60 | text = pattern.sub(replacement, text) | |
61 |
|
61 | |||
62 | return text |
|
62 | return text | |
63 |
|
63 |
@@ -122,19 +122,22 b' def strip_dollars(text):' | |||||
122 | return text.strip('$') |
|
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 | def strip_files_prefix(text): |
|
128 | def strip_files_prefix(text): | |
128 | """ |
|
129 | """ | |
129 | Fix all fake URLs that start with `files/`, |
|
130 | Fix all fake URLs that start with `files/`, stripping out the `files/` prefix. | |
130 | stripping out the `files/` prefix. |
|
131 | Applies to both urls (for html) and relative paths (for markdown paths). | |
131 |
|
132 | |||
132 | Parameters |
|
133 | Parameters | |
133 | ---------- |
|
134 | ---------- | |
134 | text : str |
|
135 | text : str | |
135 | Text in which to replace 'src="files/real...' with 'src="real...' |
|
136 | Text in which to replace 'src="files/real...' with 'src="real...' | |
136 | """ |
|
137 | """ | |
137 |
|
|
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 | def comment_lines(text, prefix='# '): |
|
143 | def comment_lines(text, prefix='# '): |
@@ -41,5 +41,3 b' class TestLatex(TestsBase):' | |||||
41 | def _try_escape_latex(self, test, result): |
|
41 | def _try_escape_latex(self, test, result): | |
42 | """Try to remove latex from string""" |
|
42 | """Try to remove latex from string""" | |
43 | self.assertEqual(escape_latex(test), result) |
|
43 | self.assertEqual(escape_latex(test), result) | |
44 |
|
||||
45 |
|
@@ -87,7 +87,20 b' class TestStrings(TestsBase):' | |||||
87 | ('/files', '/files'), |
|
87 | ('/files', '/files'), | |
88 | ('test="/files"', 'test="/files"'), |
|
88 | ('test="/files"', 'test="/files"'), | |
89 | ('My files are in `files/`', 'My files are in `files/`'), |
|
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 | for test in tests: |
|
104 | for test in tests: | |
92 | self._try_files_prefix(test[0], test[1]) |
|
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 | ((* elif cell.level == 6 -*)) |
|
202 | ((* elif cell.level == 6 -*)) | |
203 | ((* block h6 -*))\\*\textit((* endblock h6 -*)) |
|
203 | ((* block h6 -*))\\*\textit((* endblock h6 -*)) | |
204 | ((*- endif -*)) |
|
204 | ((*- endif -*)) | |
205 | {((( cell.source | replace('\n', ' ') | citation2latex | markdown2latex )))} |
|
205 | {((( cell.source | replace('\n', ' ') | citation2latex | strip_files_prefix | markdown2latex )))} | |
206 |
|
206 | |||
207 | ((* endblock headingcell *)) |
|
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 | % Render markdown |
|
216 | % Render markdown | |
217 | ((* block markdowncell scoped *)) |
|
217 | ((* block markdowncell scoped *)) | |
218 | ((( cell.source | citation2latex | markdown2latex ))) |
|
218 | ((( cell.source | citation2latex | strip_files_prefix | markdown2latex ))) | |
219 | ((* endblock markdowncell *)) |
|
219 | ((* endblock markdowncell *)) | |
220 |
|
220 | |||
221 | % Don't display unknown types |
|
221 | % Don't display unknown types |
General Comments 0
You need to be logged in to leave comments.
Login now