File tree Expand file tree Collapse file tree 4 files changed +25
-1
lines changed Expand file tree Collapse file tree 4 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -14,3 +14,4 @@ The following changes have been made:
14
14
- Dropped support for Python 2
15
15
- Verified support for Python 3.7 - 3.12
16
16
- Fixed bug where variables could be incorrectly resolved from other scopes (see [ #3 ] ( https://github.com/zanieb/chevron-blue/pull/3 ) )
17
+ - Added global ` --no-escape ` option to disable HTML escaping (see [ #4 ] ( https://github.com/zanieb/chevron-blue/pull/4 ) )
Original file line number Diff line number Diff line change @@ -113,6 +113,12 @@ def is_dir(arg):
113
113
action = "store_true" ,
114
114
)
115
115
116
+ parser .add_argument (
117
+ "--no-escape" ,
118
+ help = "Do not HTML escape values." ,
119
+ action = "store_true" ,
120
+ )
121
+
116
122
args = vars (parser .parse_args ())
117
123
118
124
try :
Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ def render(
123
123
scopes = None ,
124
124
warn = False ,
125
125
keep = False ,
126
+ no_escape = False ,
126
127
):
127
128
"""Render a mustache template.
128
129
@@ -170,6 +171,8 @@ def render(
170
171
171
172
warn -- Issue a warning to stderr when a template substitution isn't found in the data
172
173
174
+ no_escape -- Do not HTML escape variable values
175
+
173
176
keep -- Keep unreplaced tags when a template substitution isn't found in the data
174
177
175
178
@@ -230,7 +233,7 @@ def render(
230
233
thing = scopes [1 ]
231
234
if not isinstance (thing , str ):
232
235
thing = str (thing )
233
- output += _html_escape (thing )
236
+ output += thing if no_escape else _html_escape (thing )
234
237
235
238
# If we're a no html escape tag
236
239
elif tag == "no escape" :
Original file line number Diff line number Diff line change @@ -511,6 +511,20 @@ def test_keep_from_partials(self):
511
511
expected = "1st {{ missing_key }} 3rd"
512
512
self .assertEqual (result , expected )
513
513
514
+ # https://github.com/noahmorrison/chevron/pull/94
515
+ def test_no_escape (self ):
516
+ args = {
517
+ "template" : "{{ html_escaped }}" ,
518
+ "data" : {
519
+ "html_escaped" : '< > & "' ,
520
+ },
521
+ "no_escape" : True ,
522
+ }
523
+
524
+ result = chevron_blue .render (** args )
525
+ expected = '< > & "'
526
+ self .assertEqual (result , expected )
527
+
514
528
515
529
# Run unit tests from command line
516
530
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments