OLD | NEW |
1 # This file is part of the Adblock Plus web scripts, | 1 # This file is part of the Adblock Plus web scripts, |
2 # Copyright (C) 2006-2016 Eyeo GmbH | 2 # Copyright (C) 2006-2016 Eyeo GmbH |
3 # | 3 # |
4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
7 # | 7 # |
8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 310 |
311 def get_html(self, source, filename): | 311 def get_html(self, source, filename): |
312 def remove_unnecessary_entities(match): | 312 def remove_unnecessary_entities(match): |
313 char = unichr(int(match.group(1))) | 313 char = unichr(int(match.group(1))) |
314 if char in html_escapes: | 314 if char in html_escapes: |
315 return match.group(0) | 315 return match.group(0) |
316 else: | 316 else: |
317 return char | 317 return char |
318 | 318 |
319 escapes = {} | 319 escapes = {} |
320 for char in markdown.Markdown.ESCAPED_CHARS: | 320 md = markdown.Markdown(output='html5', extensions=['extra']) |
| 321 for char in md.ESCAPED_CHARS: |
321 escapes[char] = '&#' + str(ord(char)) + ';' | 322 escapes[char] = '&#' + str(ord(char)) + ';' |
322 for key, value in html_escapes.iteritems(): | 323 for key, value in html_escapes.iteritems(): |
323 escapes[key] = value | 324 escapes[key] = value |
324 | 325 |
325 md = markdown.Markdown(output='html5', extensions=['extra']) | |
326 md.preprocessors['html_block'].markdown_in_raw = True | 326 md.preprocessors['html_block'].markdown_in_raw = True |
327 | 327 |
328 def to_html(s): | 328 def to_html(s): |
329 return re.sub(r'</?p>', '', md.convert(s)) | 329 return re.sub(r'</?p>', '', md.convert(s)) |
330 | 330 |
331 result = self.insert_localized_strings(source, escapes, to_html) | 331 result = self.insert_localized_strings(source, escapes, to_html) |
332 result = md.convert(result) | 332 result = md.convert(result) |
333 result = re.sub(r'&#(\d+);', remove_unnecessary_entities, result) | 333 result = re.sub(r'&#(\d+);', remove_unnecessary_entities, result) |
334 result = self.process_links(result) | 334 result = self.process_links(result) |
335 return result | 335 return result |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 stack.pop() | 451 stack.pop() |
452 stack[-1]['subitems'].append(item) | 452 stack[-1]['subitems'].append(item) |
453 stack.append(item) | 453 stack.append(item) |
454 return structured | 454 return structured |
455 | 455 |
456 converters = { | 456 converters = { |
457 'html': RawConverter, | 457 'html': RawConverter, |
458 'md': MarkdownConverter, | 458 'md': MarkdownConverter, |
459 'tmpl': TemplateConverter, | 459 'tmpl': TemplateConverter, |
460 } | 460 } |
OLD | NEW |