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

Delta Between Two Patch Sets: cms/converters.py

Issue 29512597: Issue 4491 - Adds handling for block commented page metadata (Closed)
Left Patch Set: Created Aug. 11, 2017, 8:36 a.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 == '<!--\n' or line == '-->\n': 125 if line.strip() in {'<!--', '-->'}:
Vasily Kuznetsov 2017/08/11 17:38:21 Maybe we can use `.strip()` to take care of possib
Jon Sonesen 2017/08/14 05:58:52 Acknowledged.
126 lines[i] = '' 126 lines[i] = ''
127 continue 127 continue
128 if not re.search(r'^\s*[\w\-]+\s*=', line): 128 if not re.search(r'^\s*[\w\-]+\s*=', line):
129 break 129 break
130 name, value = line.split('=', 1) 130 name, value = line.split('=', 1)
131 value = value.strip() 131 value = value.strip()
132 if value.startswith('[') and value.endswith(']'): 132 if value.startswith('[') and value.endswith(']'):
133 value = [element.strip() for element in value[1:-1].split(',')] 133 value = [element.strip() for element in value[1:-1].split(',')]
134 lines[i] = '\n' 134 lines[i] = '\n'
135 page_data[name.strip()] = value 135 page_data[name.strip()] = value
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 stack.pop() 556 stack.pop()
557 stack[-1]['subitems'].append(item) 557 stack[-1]['subitems'].append(item)
558 stack.append(item) 558 stack.append(item)
559 return structured 559 return structured
560 560
561 converters = { 561 converters = {
562 'html': RawConverter, 562 'html': RawConverter,
563 'md': MarkdownConverter, 563 'md': MarkdownConverter,
564 'tmpl': TemplateConverter, 564 'tmpl': TemplateConverter,
565 } 565 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld