Automatically unescape URIs whose scheme is "secretary".
This commit is contained in:
Christopher Ramírez 2017-02-13 11:22:22 -06:00
parent a827b28f48
commit 96ceaf41f1

View file

@ -397,8 +397,9 @@ class Renderer(object):
def _unescape_entities(self, xml_text): def _unescape_entities(self, xml_text):
""" """
Unescape '&', '<', '"' and '>' within jinja instructions. Unescape links and '&', '<', '"' and '>' within jinja
The regexs rules used here are compiled in _compile_escape_expressions. instructions. The regexs rules used here are compiled in
_compile_escape_expressions.
""" """
for regexp, replacement in self.escape_map.items(): for regexp, replacement in self.escape_map.items():
while True: while True:
@ -406,6 +407,23 @@ class Renderer(object):
if not substitutions: if not substitutions:
break break
return self._unescape_links(xml_text)
def _unescape_links(self, xml_text):
"""Fix Libreoffice auto escaping of xlink:href attribute values.
This unescaping is only done on 'secretary' scheme URLs."""
import urllib
robj = re.compile(r'(?is)(xlink:href=\")secretary:(.*?)(\")')
def replacement(match):
return ''.join([match.group(1), urllib.unquote(match.group(2)),
match.group(3)])
while True:
xml_text, rep = robj.subn(replacement, xml_text)
if not rep:
break
return xml_text return xml_text
@staticmethod @staticmethod