Skip to content

Commit

Permalink
Improved preserve_handlebar_syntax regex
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe authored and IwanBurg committed Apr 11, 2022
1 parent f4ded0b commit c98f319
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions premailer/premailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,11 @@ def transform(self, html=None, pretty_print=True, **kwargs):
# <a href="{{ "<Test>" }}"></a>
if self.preserve_handlebar_syntax:
stripped = re.sub(
r'="{{(.*?)}}"',
lambda match: '="{{' + escape(match.groups()[0]) + '}}"',
r'="([^"]*){{(.*?)}}([^"]*?)"',
lambda match: '="' +
match.groups()[0] +
'{{' + escape(match.groups()[1]) + '}}' +
match.groups()[2] + '"',
stripped,
)

Expand Down Expand Up @@ -563,8 +566,11 @@ def transform(self, html=None, pretty_print=True, **kwargs):
# attributes, with their single-character equivalents.
if self.preserve_handlebar_syntax:
out = re.sub(
r'="%7B%7B(.+?)%7D%7D"',
lambda match: '="{{' + unescape(unquote(match.groups()[0])) + '}}"',
r'="([^"]*)%7B%7B(.+?)%7D%7D([^"]*?)"',
lambda match: '="' +
match.groups()[0] +
'{{' + unescape(unquote(match.groups()[1])) + '}}' +
match.groups()[2] + '"',
out,
)
return out
Expand Down

0 comments on commit c98f319

Please sign in to comment.