Skip to content

Commit

Permalink
fix: insert AllowBlanklineBefore atom
Browse files Browse the repository at this point in the history
  • Loading branch information
Erin van der Veen committed May 15, 2024
1 parent f441c42 commit 74ae511
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions topiary-core/src/atom_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ impl AtomCollection {
match name {
"allow_blank_line_before" => {
if self.blank_lines_before.contains(&node.id()) {
// If there already was a blankline, keep it
self.prepend(Atom::Blankline, node, predicates);
} else {
// Otherwise, allow the query processing to insert blank lines that we won't remove
self.append(Atom::AllowBlanklineBefore, node, predicates);
}
}
"append_delimiter" => self.append(
Expand Down
4 changes: 4 additions & 0 deletions topiary-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ pub enum Atom {
/// We don't allow consecutive `Hardline`, but a `Blankline` will render two
/// newlines to produce a blank line.
Blankline,
/// Sometimes, Topiary needs to be instructed that a blank line is allowed before the current node.
/// Previously, this was done in the collection phase, however, we also don't want to remove lines that were added by queries.
/// As such, this node informs the post-processing step not to remove any double Hardlines or single Blanklines.
AllowBlanklineBefore,
/// A "no-op" atom that will not produce any output.
#[default]
Empty,
Expand Down

0 comments on commit 74ae511

Please sign in to comment.