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 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 if callback: | 174 if callback: |
175 callback(page, locale, name, result, comment, fixed_strings) | 175 callback(page, locale, name, result, comment, fixed_strings) |
176 | 176 |
177 # Insert fixed strings | 177 # Insert fixed strings |
178 for i, fixed_string in enumerate(fixed_strings, 1): | 178 for i, fixed_string in enumerate(fixed_strings, 1): |
179 result = result.replace('{{{}}}'.format(i), fixed_string) | 179 result = result.replace('{{{}}}'.format(i), fixed_string) |
180 | 180 |
181 # Insert attributes | 181 # Insert attributes |
182 result = escape(result) | 182 result = escape(result) |
183 | 183 |
184 def stringify_attribute(attribute): | 184 def stringify_attribute(name, value): |
185 name, value = attribute | |
186 return '{}="{}"'.format( | 185 return '{}="{}"'.format( |
187 escape(name), | 186 escape(name), |
188 escape(self.insert_localized_strings(value, {})) | 187 escape(self.insert_localized_strings(value, {})) |
189 ) | 188 ) |
190 | 189 |
191 for tag in self.whitelist: | 190 for tag in self.whitelist: |
192 allowed_contents = '(?:[^<>]|{})'.format('|'.join( | 191 allowed_contents = '(?:[^<>]|{})'.format('|'.join( |
193 '<(?:{}[^<>]*?|/{})>'.format(t, t) | 192 '<(?:{}[^<>]*?|/{})>'.format(t, t) |
194 for t in map(re.escape, self.whitelist - {tag}) | 193 for t in map(re.escape, self.whitelist - {tag}) |
195 )) | 194 )) |
196 saved = saved_attributes.get(tag, []) | 195 saved = saved_attributes.get(tag, []) |
197 for attrs in saved: | 196 for attrs in saved: |
198 attrs = map(stringify_attribute, attrs) | 197 attrs = [stringify_attribute(*attr) for attr in attrs] |
199 result = re.sub( | 198 result = re.sub( |
200 r'{}({}*?){}'.format(re_escape('<{}>'.format(tag)), | 199 r'{}({}*?){}'.format(re_escape('<{}>'.format(tag)), |
201 allowed_contents, | 200 allowed_contents, |
202 re_escape('</{}>'.format(tag))), | 201 re_escape('</{}>'.format(tag))), |
203 lambda match: r'<{}{}>{}</{}>'.format( | 202 lambda match: r'<{}{}>{}</{}>'.format( |
204 tag, | 203 tag, |
205 ' ' + ' '.join(attrs) if attrs else '', | 204 ' ' + ' '.join(attrs) if attrs else '', |
206 match.group(1), | 205 match.group(1), |
207 tag | 206 tag |
208 ), | 207 ), |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 stack[-1]['subitems'].append(item) | 528 stack[-1]['subitems'].append(item) |
530 stack.append(item) | 529 stack.append(item) |
531 return structured | 530 return structured |
532 | 531 |
533 | 532 |
534 converters = { | 533 converters = { |
535 'html': RawConverter, | 534 'html': RawConverter, |
536 'md': MarkdownConverter, | 535 'md': MarkdownConverter, |
537 'tmpl': TemplateConverter, | 536 'tmpl': TemplateConverter, |
538 } | 537 } |
LEFT | RIGHT |