Skip to content

Commit

Permalink
refactor: simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Sep 20, 2024
1 parent 343d426 commit f6008e1
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions markup_fmt/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ impl<'s> DocGen<'s> for AstroExpr<'s> {
where
F: for<'a> FnMut(&'a str, Hints) -> Result<Cow<'a, str>, E>,
{
let indent_width = ctx.indent_width;

const PLACEHOLDER: &str = "$AstroTpl$";
let script = self
.children
Expand Down Expand Up @@ -258,15 +256,28 @@ impl<'s> DocGen<'s> for AstroExpr<'s> {
.nest_with_ctx(ctx)
.append(Doc::line_or_nil())
.append(Doc::flat_or_break(Doc::nil(), Doc::text(")")))
.group()
.nest_with_ctx(ctx),
.group(),
)
} else {
None
}
});

Doc::text("{")
.append(Doc::line_or_nil())
.concat(
formatted_script
.split(PLACEHOLDER)
.map(|script| {
if script.contains('\n') {
Doc::list(reflow_owned(script).collect())
} else {
Doc::text(script.to_string())
}
})
.interleave(templates),
)
.nest_with_ctx(ctx)
.append(
if self.has_line_comment
|| formatted_script
Expand All @@ -280,20 +291,6 @@ impl<'s> DocGen<'s> for AstroExpr<'s> {
Doc::line_or_nil()
},
)
.nest(indent_width)
.concat(
formatted_script
.split(PLACEHOLDER)
.map(|script| {
if script.contains('\n') {
Doc::list(reflow_owned(script).collect())
} else {
Doc::text(script.to_string())
}
})
.interleave(templates),
)
.append(Doc::line_or_nil())
.append(Doc::text("}"))
.group()
}
Expand Down

0 comments on commit f6008e1

Please sign in to comment.