Created
January 20, 2016 10:20
-
-
Save saevarom/2d625376a99aea782489 to your computer and use it in GitHub Desktop.
django template escaping and un-escaping for project template templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Convert a regular django template to a project-template template | |
# Usage: ./django_template_escape.sh filename | |
# The file is edited in-place. | |
sed -i '' "s/{%/openblock/g" "$1" | |
sed -i '' "s/%}/closeblock/g" "$1" | |
sed -i '' "s/openblock/{% templatetag openblock %}/g" "$1" | |
sed -i '' "s/closeblock/{% templatetag closeblock %}/g" "$1" | |
sed -i '' "s/{{/{% templatetag openvariable %}/g" "$1" | |
sed -i '' "s/}}/{% templatetag closevariable %}/g" "$1" | |
sed -i '' "s/{#/{% templatetag opencomment %}/g" "$1" | |
sed -i '' "s/#}/{% templatetag closecomment %}/g" "$1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Convert django project-template template to a regular template | |
# Usage: ./django_template_unescape.sh filename | |
# The file is edited in-place. | |
sed -i '' "s/{% templatetag openblock %}/{%/g" "$1" | |
sed -i '' "s/{% templatetag closeblock %}/%}/g" "$1" | |
sed -i '' "s/{% templatetag openvariable %}/{{/g" "$1" | |
sed -i '' "s/{% templatetag closevariable %}/}}/g" "$1" | |
sed -i '' "s/{% templatetag opencomment %}/{#/g" "$1" | |
sed -i '' "s/{% templatetag closecomment %}/#}/g" "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment