@@ -14,6 +14,7 @@ use quote::quote;
14
14
15
15
use crate :: config:: WhitespaceHandling ;
16
16
use crate :: heritage:: { Context , Heritage } ;
17
+ use crate :: html:: write_escaped_str;
17
18
use crate :: input:: { Source , TemplateInput } ;
18
19
use crate :: { CompileError , MsgValidEscapers , CRATE } ;
19
20
@@ -1161,8 +1162,43 @@ impl<'a> Generator<'a> {
1161
1162
}
1162
1163
1163
1164
fn write_expr ( & mut self , ws : Ws , s : & ' a WithSpan < ' a , Expr < ' a > > ) {
1165
+ let mut writable = Writable :: Expr ( s) ;
1166
+ ( || {
1167
+ let & Expr :: StrLit ( input) = & * * s else {
1168
+ return ;
1169
+ } ;
1170
+
1171
+ let Some ( escaper) = self . input . escaper . strip_prefix ( CRATE ) else {
1172
+ return ;
1173
+ } ;
1174
+ let is_html = match escaper {
1175
+ "::filters::Html" => true ,
1176
+ "::filters::Text" => false ,
1177
+ _ => return ,
1178
+ } ;
1179
+
1180
+ // TODO: implement parsing properly
1181
+ let input = format ! ( r#""{input}""# ) ;
1182
+ let Ok ( input) = input. parse :: < proc_macro2:: TokenStream > ( ) else {
1183
+ return ;
1184
+ } ;
1185
+ let Ok ( input) = syn:: parse2 :: < syn:: LitStr > ( input) else {
1186
+ return ;
1187
+ } ;
1188
+ let input = input. value ( ) ;
1189
+
1190
+ if is_html {
1191
+ let mut escaped = String :: with_capacity ( input. len ( ) + 20 ) ;
1192
+ if write_escaped_str ( & mut escaped, & input) . is_ok ( ) {
1193
+ writable = Writable :: Lit ( Cow :: Owned ( escaped) ) ;
1194
+ }
1195
+ } else {
1196
+ writable = Writable :: Lit ( Cow :: Owned ( input) ) ;
1197
+ }
1198
+ } ) ( ) ;
1199
+
1164
1200
self . handle_ws ( ws) ;
1165
- self . buf_writable . push ( Writable :: Expr ( s ) ) ;
1201
+ self . buf_writable . push ( writable ) ;
1166
1202
}
1167
1203
1168
1204
// Write expression buffer and empty
0 commit comments