Skip to content

Commit

Permalink
Merge pull request #518 from mkantor/omit-pre-whitespace-prevents-mul…
Browse files Browse the repository at this point in the history
…tiline-partial-indent

Disable partial indent with leading `~`
  • Loading branch information
sunng87 authored Jul 17, 2022
2 parents ac5bd3c + eaf6782 commit 29fef48
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [Unreleased](https://github.com/sunng87/handlebars-rust/compare/4.3.2...Unreleased) - ReleaseDate

* [Fixed] Disable partial expression indentation with `{{~> partial}}` to
bring behavior closer in line with original javascript version. [#518]

## [4.3.2](https://github.com/sunng87/handlebars-rust/compare/4.3.1...4.3.2) - 2022-07-14

* [Added] Render functions that reuse `Context` for custom `std::io::Write`:
Expand Down
17 changes: 17 additions & 0 deletions src/partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,23 @@ outer third line"#,
.unwrap()
);

hb.register_template_string(
"t4",
r#"{{#*inline "thepartial"}}
inner first line
inner second line
{{/inline}}
{{~> thepartial}}
outer third line"#,
)
.unwrap();
assert_eq!(
r#" inner first line
inner second line
outer third line"#,
hb.render("t4", &()).unwrap()
);

let mut hb2 = Registry::new();
hb2.set_prevent_indent(true);

Expand Down
5 changes: 4 additions & 1 deletion src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,10 @@ impl Template {

// indent for partial expression >
let mut indent = None;
if rule == Rule::partial_expression && !options.prevent_indent {
if rule == Rule::partial_expression
&& !options.prevent_indent
&& !exp.omit_pre_ws
{
indent = support::str::find_trailing_whitespace_chars(
&source[..span.start()],
);
Expand Down

0 comments on commit 29fef48

Please sign in to comment.