Skip to content

Commit

Permalink
fix unstable formatting of interpolation in non-ws-sensitive tag
Browse files Browse the repository at this point in the history
(fix #26)
  • Loading branch information
g-plane committed Jun 21, 2024
1 parent 5bc7f82 commit 82f8423
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
24 changes: 13 additions & 11 deletions markup_fmt/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,17 +512,19 @@ impl<'s> DocGen<'s> for Element<'s> {
ctx,
&state,
));
if self.children.iter().all(|child| {
matches!(
child,
Node::VueInterpolation(..)
| Node::SvelteInterpolation(..)
| Node::Comment(..)
| Node::AstroExpr(..)
| Node::JinjaInterpolation(..)
| Node::VentoInterpolation(..)
)
}) {
if is_whitespace_sensitive
&& self.children.iter().all(|child| {
matches!(
child,
Node::VueInterpolation(..)
| Node::SvelteInterpolation(..)
| Node::Comment(..)
| Node::AstroExpr(..)
| Node::JinjaInterpolation(..)
| Node::VentoInterpolation(..)
)
})
{
// This lets it format like this:
// ```
// <span>{{
Expand Down
2 changes: 2 additions & 0 deletions markup_fmt/tests/fmt/jinja/interpolation/fixture.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
</div>

<span>{{ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx }}</span>

<div>{{ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx }}</div>
4 changes: 4 additions & 0 deletions markup_fmt/tests/fmt/jinja/interpolation/fixture.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ source: markup_fmt/tests/fmt.rs
<span>{{
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}}</span>

<div>
{{ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx }}
</div>

0 comments on commit 82f8423

Please sign in to comment.