mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Ignore linebreak directly after markup statement
This commit is contained in:
parent
72361106bc
commit
46d469f4be
@ -56,7 +56,17 @@ node! {
|
|||||||
impl Markup {
|
impl Markup {
|
||||||
/// The children.
|
/// The children.
|
||||||
pub fn children(&self) -> impl DoubleEndedIterator<Item = MarkupNode> + '_ {
|
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(_, _))
|
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.
|
/// A human-readable name for the kind.
|
||||||
pub fn name(&self) -> &'static str {
|
pub fn name(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user