Skip to content

Instantly share code, notes, and snippets.

/newline.diff Secret

Created September 1, 2014 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/fb6b70d78e954238f527 to your computer and use it in GitHub Desktop.
Save anonymous/fb6b70d78e954238f527 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/Template.pm b/lib/Mojo/Template.pm
index e9d1780..6838211 100644
--- a/lib/Mojo/Template.pm
+++ b/lib/Mojo/Template.pm
@@ -46,6 +46,7 @@ sub build {
# Text (quote and fix line ending)
if ($op eq 'text') {
$value = $newline ? quotemeta($value) . '\n' : quotemeta $value;
+ $value =~ s/\\\n/\n/g;
$lines[-1] .= "\$_M .= \"" . $value . "\";" if length $value;
}
@@ -219,7 +220,9 @@ sub parse {
}
}
- push @tree, \@token;
+ push @tree, \@token and next
+ if !@tree || grep { @$_ != 2 || $_->[0] ne 'text' } $tree[-1], \@token;
+ $tree[-1][1] .= $token[1];
}
return $self;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment