@@ -906,6 +906,7 @@ struct ParserConfig {
906
906
*/
907
907
struct RenderConfig {
908
908
bool throw_at_missing_includes {true };
909
+ bool escape_strings {};
909
910
};
910
911
911
912
} // namespace inja
@@ -2150,7 +2151,16 @@ class Renderer : public NodeVisitor {
2150
2151
2151
2152
void print_data (const std::shared_ptr<json> value) {
2152
2153
if (value->is_string ()) {
2153
- *output_stream << value->get_ref <const json::string_t &>();
2154
+ std::string val;
2155
+ if (config.escape_strings ) {
2156
+ val = value->dump ();
2157
+ val = val.substr (0 ,1 ) == " \" " && val.substr (val.length ()-1 ,1 ) == " \" "
2158
+ ? val.substr (1 , val.length ()-2 )
2159
+ : val;
2160
+ } else {
2161
+ val = value->get_ref <const json::string_t &>();
2162
+ }
2163
+ *output_stream << val;
2154
2164
} else if (value->is_number_integer ()) {
2155
2165
*output_stream << value->get <const json::number_integer_t >();
2156
2166
} else if (value->is_null ()) {
@@ -2803,6 +2813,11 @@ class Environment {
2803
2813
lexer_config.notation = notation;
2804
2814
}
2805
2815
2816
+ // / Sets the config for rendering strings raw or escaped
2817
+ void set_escape_strings (bool escape_strings) {
2818
+ render_config.escape_strings = escape_strings;
2819
+ }
2820
+
2806
2821
// / Sets the element notation syntax
2807
2822
void set_search_included_templates_in_files (bool search_in_files) {
2808
2823
parser_config.search_included_templates_in_files = search_in_files;
0 commit comments