diff --git a/rslib/src/template.rs b/rslib/src/template.rs index 5e53f119c..86ebc4704 100644 --- a/rslib/src/template.rs +++ b/rslib/src/template.rs @@ -316,6 +316,16 @@ fn render_into( }); } } + Replacement { key: "", filters } if !filters.is_empty() => { + // if a filter is provided, we accept an empty field name to + // mean 'pass an empty string to the filter, and it will add + // its own text' + rendered_nodes.push(RenderedNode::Replacement { + field_name: "".to_string(), + current_text: "".to_string(), + filters: filters.iter().map(|&f| f.to_string()).collect(), + }) + } Replacement { key, filters } => { // apply built in filters if field exists let (text, remaining_filters) = match context.fields.get(key) { @@ -741,6 +751,17 @@ mod test { text: "{unknown field foo:text:X}".to_owned() }] ); + + // a blank field is allowed if it has filters + tmpl = PT::from_text("{{filter:}}").unwrap(); + assert_eq!( + tmpl.render(&ctx), + vec![FN::Replacement { + field_name: "".to_string(), + current_text: "".to_string(), + filters: vec!["filter".to_string()] + }] + ); } fn get_complete_template(nodes: &Vec) -> Option<&str> {