mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Ignore linebreak directly after markup statement
This commit is contained in:
parent
72361106bc
commit
46d469f4be
@ -56,7 +56,17 @@ node! {
|
||||
impl Markup {
|
||||
/// The children.
|
||||
pub fn children(&self) -> impl DoubleEndedIterator<Item = MarkupNode> + '_ {
|
||||
self.0.children().filter_map(SyntaxNode::cast)
|
||||
let mut was_stmt = false;
|
||||
self.0
|
||||
.children()
|
||||
.filter(move |node| {
|
||||
// Ignore linebreak directly after statements without semicolons.
|
||||
let kind = node.kind();
|
||||
let keep = !was_stmt || !matches!(kind, NodeKind::Space { newlines: 1 });
|
||||
was_stmt = kind.is_stmt();
|
||||
keep
|
||||
})
|
||||
.filter_map(SyntaxNode::cast)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,6 +314,18 @@ impl NodeKind {
|
||||
matches!(self, NodeKind::Error(_, _))
|
||||
}
|
||||
|
||||
/// Does this node need termination through a semicolon or linebreak?
|
||||
pub fn is_stmt(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
NodeKind::LetBinding
|
||||
| NodeKind::SetRule
|
||||
| NodeKind::ShowRule
|
||||
| NodeKind::ModuleImport
|
||||
| NodeKind::ModuleInclude
|
||||
)
|
||||
}
|
||||
|
||||
/// A human-readable name for the kind.
|
||||
pub fn name(&self) -> &'static str {
|
||||
match self {
|
||||
|
Loading…
x
Reference in New Issue
Block a user