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-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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 # Insert attributes | 181 # Insert attributes |
182 result = escape(result) | 182 result = escape(result) |
183 | 183 |
184 def stringify_attribute((name, value)): | 184 def stringify_attribute((name, value)): |
185 return '{}="{}"'.format( | 185 return '{}="{}"'.format( |
186 escape(name), | 186 escape(name), |
187 escape(self.insert_localized_strings(value, {})) | 187 escape(self.insert_localized_strings(value, {})) |
188 ) | 188 ) |
189 | 189 |
190 for tag in self.whitelist: | 190 for tag in self.whitelist: |
191 allowed_contents = '(?:[^<>]|{})'.format('|'.join(( | 191 allowed_contents = '(?:[^<>]|{})'.format('|'.join( |
192 '<(?:{}[^<>]*?|/{})>'.format(t, t) | 192 '<(?:{}[^<>]*?|/{})>'.format(t, t) |
193 for t in map(re.escape, self.whitelist - {tag}) | 193 for t in map(re.escape, self.whitelist - {tag}) |
194 ))) | 194 )) |
195 saved = saved_attributes.get(tag, []) | 195 saved = saved_attributes.get(tag, []) |
196 for attrs in saved: | 196 for attrs in saved: |
197 attrs = map(stringify_attribute, attrs) | 197 attrs = map(stringify_attribute, attrs) |
198 result = re.sub( | 198 result = re.sub( |
199 r'{}({}*?){}'.format(re_escape('<{}>'.format(tag)), | 199 r'{}({}*?){}'.format(re_escape('<{}>'.format(tag)), |
200 allowed_contents, | 200 allowed_contents, |
201 re_escape('</{}>'.format(tag))), | 201 re_escape('</{}>'.format(tag))), |
202 lambda match: r'<{}{}>{}</{}>'.format( | 202 lambda match: r'<{}{}>{}</{}>'.format( |
203 tag, | 203 tag, |
204 ' ' + ' '.join(attrs) if attrs else '', | 204 ' ' + ' '.join(attrs) if attrs else '', |
(...skipping 323 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 } |
OLD | NEW |