Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-present eyeo GmbH | 2 # Copyright (C) 2006-present 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 |
11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
12 # | 12 # |
13 # You should have received a copy of the GNU General Public License | 13 # You should have received a copy of the GNU General Public License |
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 |
16 from __future__ import unicode_literals | 16 from __future__ import unicode_literals |
17 | 17 |
18 import os | 18 import os |
19 import HTMLParser | 19 import HTMLParser |
20 import re | 20 import re |
21 import urlparse | 21 import urlparse |
22 | 22 |
23 import jinja2 | 23 import jinja2 |
24 import markdown | 24 import markdown |
25 | 25 |
26 from cms import utils | 26 from cms import utils |
Vasily Kuznetsov
2017/10/27 18:35:01
It makes more sense for `utils` to be imported int
mathias
2017/10/30 15:37:00
Acknowledged.
| |
27 | 27 |
28 # Monkey-patch Markdown's isBlockLevel function to ensure that no paragraphs | 28 # Monkey-patch Markdown's isBlockLevel function to ensure that no paragraphs |
29 # are inserted into the <head> tag | 29 # are inserted into the <head> tag |
30 orig_isBlockLevel = markdown.util.isBlockLevel | 30 orig_isBlockLevel = markdown.util.isBlockLevel |
31 | 31 |
32 | 32 |
33 def isBlockLevel(tag): | 33 def isBlockLevel(tag): |
34 if tag == 'head': | 34 if tag == 'head': |
35 return True | 35 return True |
36 return orig_isBlockLevel(tag) | 36 return orig_isBlockLevel(tag) |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 def resolve_include(match): | 270 def resolve_include(match): |
271 name = match.group(1) | 271 name = match.group(1) |
272 for format_, converter_class in converters.iteritems(): | 272 for format_, converter_class in converters.iteritems(): |
273 if self._params['source'].has_include(name, format_): | 273 if self._params['source'].has_include(name, format_): |
274 data, filename = ( | 274 data, filename = ( |
275 self._params['source'].read_include(name, format_)) | 275 self._params['source'].read_include(name, format_)) |
276 | 276 |
277 # XXX: allowing includes to modify params of the whole page | 277 # XXX: allowing includes to modify params of the whole page |
278 # seems like a bad idea but we have to support this because | 278 # seems like a bad idea but we have to support this because |
279 # it's used by www.adblockplus.org. | 279 # it's used by www.adblockplus.org. |
280 metadata, rest = utils.extract_page_metadata(data) | 280 metadata, rest = utils.extract_page_metadata(data) |
Vasily Kuznetsov
2017/10/27 18:35:01
We have to maintain the ability of includes to wri
mathias
2017/10/30 15:37:00
Acknowledged.
| |
281 self._params.update(metadata) | 281 self._params.update(metadata) |
282 | 282 |
283 converter = converter_class(rest, filename, self._params) | 283 converter = converter_class(rest, filename, self._params) |
284 result = converter() | 284 result = converter() |
285 self.missing_translations += converter.missing_translations | 285 self.missing_translations += converter.missing_translations |
286 self.total_translations += converter.total_translations | 286 self.total_translations += converter.total_translations |
287 return result | 287 return result |
288 raise Exception('Failed to resolve include {}' | 288 raise Exception('Failed to resolve include {}' |
289 ' on page {}'.format(name, self._params['page'])) | 289 ' on page {}'.format(name, self._params['page'])) |
290 | 290 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 | 461 |
462 def get_pages_metadata(self, filters=None): | 462 def get_pages_metadata(self, filters=None): |
463 if filters is not None and not isinstance(filters, dict): | 463 if filters is not None and not isinstance(filters, dict): |
464 raise TypeError('Filters are not a dictionary') | 464 raise TypeError('Filters are not a dictionary') |
465 | 465 |
466 return_data = [] | 466 return_data = [] |
467 for page_name, _format in self._params['source'].list_pages(): | 467 for page_name, _format in self._params['source'].list_pages(): |
468 data, filename = self._params['source'].read_page(page_name, | 468 data, filename = self._params['source'].read_page(page_name, |
469 _format) | 469 _format) |
470 page_data = utils.extract_page_metadata(data)[0] | 470 page_data = utils.extract_page_metadata(data)[0] |
471 page_data['page'] = page_name | 471 page_data.setdefault('page', page_name) |
mathias
2017/10/30 15:37:00
Shouldn't this use setdefault(), in order to allow
Vasily Kuznetsov
2017/11/07 17:08:29
Yeah, you're right, this would be needed to preser
| |
472 if self.filter_metadata(filters, page_data) is True: | 472 if self.filter_metadata(filters, page_data) is True: |
473 return_data.append(page_data) | 473 return_data.append(page_data) |
474 return return_data | 474 return return_data |
475 | 475 |
476 def filter_metadata(self, filters, metadata): | 476 def filter_metadata(self, filters, metadata): |
477 # if only the page key is in the metadata then there | 477 # if only the page key is in the metadata then there |
478 # was no user defined metadata | 478 # was no user defined metadata |
479 if metadata.keys() == ['page']: | 479 if metadata.keys() == ['page']: |
480 return False | 480 return False |
481 if filters is None: | 481 if filters is None: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 stack[-1]['subitems'].append(item) | 528 stack[-1]['subitems'].append(item) |
529 stack.append(item) | 529 stack.append(item) |
530 return structured | 530 return structured |
531 | 531 |
532 | 532 |
533 converters = { | 533 converters = { |
534 'html': RawConverter, | 534 'html': RawConverter, |
535 'md': MarkdownConverter, | 535 'md': MarkdownConverter, |
536 'tmpl': TemplateConverter, | 536 'tmpl': TemplateConverter, |
537 } | 537 } |
LEFT | RIGHT |