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

Delta Between Two Patch Sets: cms/converters.py

Issue 4802066526502912: Issue 2323 - Make sure to always resolve links in translatable strings (Closed)
Left Patch Set: Created April 15, 2015, 7:11 p.m.
Right Patch Set: Added hreflang attribute Created April 15, 2015, 7:23 p.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 # 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
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)
Wladimir Palant 2015/04/15 19:13:06 Note that this step isn't really necessary for Mar
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
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 }
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