Skip to content

Commit c98f319

Browse files
peterbeIwanBurg
authored andcommitted
Improved preserve_handlebar_syntax regex
1 parent f4ded0b commit c98f319

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

premailer/premailer.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,11 @@ def transform(self, html=None, pretty_print=True, **kwargs):
345345
# <a href="{{ "<Test>" }}"></a>
346346
if self.preserve_handlebar_syntax:
347347
stripped = re.sub(
348-
r'="{{(.*?)}}"',
349-
lambda match: '="{{' + escape(match.groups()[0]) + '}}"',
348+
r'="([^"]*){{(.*?)}}([^"]*?)"',
349+
lambda match: '="' +
350+
match.groups()[0] +
351+
'{{' + escape(match.groups()[1]) + '}}' +
352+
match.groups()[2] + '"',
350353
stripped,
351354
)
352355

@@ -563,8 +566,11 @@ def transform(self, html=None, pretty_print=True, **kwargs):
563566
# attributes, with their single-character equivalents.
564567
if self.preserve_handlebar_syntax:
565568
out = re.sub(
566-
r'="%7B%7B(.+?)%7D%7D"',
567-
lambda match: '="{{' + unescape(unquote(match.groups()[0])) + '}}"',
569+
r'="([^"]*)%7B%7B(.+?)%7D%7D([^"]*?)"',
570+
lambda match: '="' +
571+
match.groups()[0] +
572+
'{{' + unescape(unquote(match.groups()[1])) + '}}' +
573+
match.groups()[2] + '"',
568574
out,
569575
)
570576
return out

0 commit comments

Comments
 (0)