LEFT | RIGHT |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
4 # Copyright (C) 2006-2015 Eyeo GmbH | 4 # Copyright (C) 2006-2015 Eyeo GmbH |
5 # | 5 # |
6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
9 # | 9 # |
10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 result = default | 139 result = default |
140 | 140 |
141 # Insert fixed strings | 141 # Insert fixed strings |
142 for i in range(len(fixed_strings)): | 142 for i in range(len(fixed_strings)): |
143 result = re.sub(r"\{%d\}" % (i + 1), fixed_strings[i], result, 1) | 143 result = re.sub(r"\{%d\}" % (i + 1), fixed_strings[i], result, 1) |
144 | 144 |
145 # Insert attributes | 145 # Insert attributes |
146 result = escape(result) | 146 result = escape(result) |
147 def stringify_attribute((name, value)): | 147 def stringify_attribute((name, value)): |
148 if name == "href": | 148 if name == "href": |
149 value = self._params["source"].resolve_link(value, locale)[1] or value | 149 link_locale, link = self._params["source"].resolve_link(value, locale) |
| 150 if link: |
| 151 return 'href="%s" hreflang="%s"' % (escape(link), escape(link_locale)) |
150 return '%s="%s"' % (escape(name), escape(value)) | 152 return '%s="%s"' % (escape(name), escape(value)) |
151 | 153 |
152 for tag in self.whitelist: | 154 for tag in self.whitelist: |
153 saved = saved_attributes.get(tag, []) | 155 saved = saved_attributes.get(tag, []) |
154 for attrs in saved: | 156 for attrs in saved: |
155 attrs = map(stringify_attribute, attrs) | 157 attrs = map(stringify_attribute, attrs) |
156 result = re.sub( | 158 result = re.sub( |
157 r"%s([^<>]*?)%s" % (re_escape("<%s>" % tag), re_escape("</%s>" % tag))
, | 159 r"%s([^<>]*?)%s" % (re_escape("<%s>" % tag), re_escape("</%s>" % tag))
, |
158 r'<%s %s>\1</%s>' % (tag, " ".join(attrs), tag), | 160 r'<%s %s>\1</%s>' % (tag, " ".join(attrs), tag), |
159 result, 1, flags=re.S | 161 result, 1, flags=re.S |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 stack.pop() | 387 stack.pop() |
386 stack[-1]["subitems"].append(item) | 388 stack[-1]["subitems"].append(item) |
387 stack.append(item) | 389 stack.append(item) |
388 return structured | 390 return structured |
389 | 391 |
390 converters = { | 392 converters = { |
391 "html": RawConverter, | 393 "html": RawConverter, |
392 "md": MarkdownConverter, | 394 "md": MarkdownConverter, |
393 "tmpl": TemplateConverter, | 395 "tmpl": TemplateConverter, |
394 } | 396 } |
LEFT | RIGHT |