Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: cms/converters.py

Issue 29512597: Issue 4491 - Adds handling for block commented page metadata (Closed)
Patch Set: ;) Created Aug. 15, 2017, 10:45 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2017 eyeo GmbH 2 # Copyright (C) 2006-2017 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 def handle_charref(self, name): 116 def handle_charref(self, name):
117 self._append_text(self.unescape('&#{};'.format(name))) 117 self._append_text(self.unescape('&#{};'.format(name)))
118 118
119 119
120 def parse_page_content(page, data): 120 def parse_page_content(page, data):
121 """Separate page content into metadata (dict) and body text (str)""" 121 """Separate page content into metadata (dict) and body text (str)"""
122 page_data = {'page': page} 122 page_data = {'page': page}
123 lines = data.splitlines(True) 123 lines = data.splitlines(True)
124 for i, line in enumerate(lines): 124 for i, line in enumerate(lines):
125 if line.strip() in {'<!--', '-->'}:
126 lines[i] = ''
127 continue
125 if not re.search(r'^\s*[\w\-]+\s*=', line): 128 if not re.search(r'^\s*[\w\-]+\s*=', line):
126 break 129 break
127 name, value = line.split('=', 1) 130 name, value = line.split('=', 1)
128 value = value.strip() 131 value = value.strip()
129 if value.startswith('[') and value.endswith(']'): 132 if value.startswith('[') and value.endswith(']'):
130 value = [element.strip() for element in value[1:-1].split(',')] 133 value = [element.strip() for element in value[1:-1].split(',')]
131 lines[i] = '\n' 134 lines[i] = '\n'
132 page_data[name.strip()] = value 135 page_data[name.strip()] = value
133 return page_data, ''.join(lines) 136 return page_data, ''.join(lines)
134 137
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 stack.pop() 556 stack.pop()
554 stack[-1]['subitems'].append(item) 557 stack[-1]['subitems'].append(item)
555 stack.append(item) 558 stack.append(item)
556 return structured 559 return structured
557 560
558 converters = { 561 converters = {
559 'html': RawConverter, 562 'html': RawConverter,
560 'md': MarkdownConverter, 563 'md': MarkdownConverter,
561 'tmpl': TemplateConverter, 564 'tmpl': TemplateConverter,
562 } 565 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld