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

Side by Side Diff: cms/converters.py

Issue 4802066526502912: Issue 2323 - Make sure to always resolve links in translatable strings (Closed)
Patch Set: Created April 15, 2015, 7:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 return re.sub(r".", 125 return re.sub(r".",
126 lambda match: escapes.get(match.group(0), match.group(0)), 126 lambda match: escapes.get(match.group(0), match.group(0)),
127 s, flags=re.S) 127 s, flags=re.S)
128 def re_escape(s): 128 def re_escape(s):
129 return re.escape(escape(s)) 129 return re.escape(escape(s))
130 130
131 # Extract tag attributes from default string 131 # Extract tag attributes from default string
132 default, saved_attributes, fixed_strings = self._attribute_parser.parse(defa ult, self._params["page"]) 132 default, saved_attributes, fixed_strings = self._attribute_parser.parse(defa ult, self._params["page"])
133 133
134 # Get translation 134 # Get translation
135 if self._params["locale"] != self._params["defaultlocale"] and name in local edata: 135 locale = self._params["locale"]
136 if locale != self._params["defaultlocale"] and name in localedata:
136 result = localedata[name].strip() 137 result = localedata[name].strip()
137 else: 138 else:
138 result = default 139 result = default
139 140
140 # Insert fixed strings 141 # Insert fixed strings
141 for i in range(len(fixed_strings)): 142 for i in range(len(fixed_strings)):
142 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)
143 144
144 # Insert attributes 145 # Insert attributes
145 result = escape(result) 146 result = escape(result)
147 def stringify_attribute((name, value)):
148 if name == "href":
149 value = self._params["source"].resolve_link(value, locale)[1] or value
Wladimir Palant 2015/04/15 19:13:06 Note that this step isn't really necessary for Mar
150 return '%s="%s"' % (escape(name), escape(value))
151
146 for tag in self.whitelist: 152 for tag in self.whitelist:
147 saved = saved_attributes.get(tag, []) 153 saved = saved_attributes.get(tag, [])
148 for attrs in saved: 154 for attrs in saved:
149 attrs = map(lambda (name, value): '%s="%s"' % (escape(name), escape(valu e)), attrs) 155 attrs = map(stringify_attribute, attrs)
150 result = re.sub( 156 result = re.sub(
151 r"%s([^<>]*?)%s" % (re_escape("<%s>" % tag), re_escape("</%s>" % tag)) , 157 r"%s([^<>]*?)%s" % (re_escape("<%s>" % tag), re_escape("</%s>" % tag)) ,
152 r'<%s %s>\1</%s>' % (tag, " ".join(attrs), tag), 158 r'<%s %s>\1</%s>' % (tag, " ".join(attrs), tag),
153 result, 1, flags=re.S 159 result, 1, flags=re.S
154 ) 160 )
155 result = re.sub( 161 result = re.sub(
156 r"%s([^<>]*?)%s" % (re_escape("<%s>" % tag), re_escape("</%s>" % tag)), 162 r"%s([^<>]*?)%s" % (re_escape("<%s>" % tag), re_escape("</%s>" % tag)),
157 r"<%s>\1</%s>" % (tag, tag), 163 r"<%s>\1</%s>" % (tag, tag),
158 result, flags=re.S 164 result, flags=re.S
159 ) 165 )
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 stack.pop() 385 stack.pop()
380 stack[-1]["subitems"].append(item) 386 stack[-1]["subitems"].append(item)
381 stack.append(item) 387 stack.append(item)
382 return structured 388 return structured
383 389
384 converters = { 390 converters = {
385 "html": RawConverter, 391 "html": RawConverter,
386 "md": MarkdownConverter, 392 "md": MarkdownConverter,
387 "tmpl": TemplateConverter, 393 "tmpl": TemplateConverter,
388 } 394 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld