mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Remove Parbreak
as a NodeKind
This commit is contained in:
parent
61761604e4
commit
aac3afcba8
@ -138,7 +138,7 @@ impl Reparser<'_> {
|
|||||||
|
|
||||||
// Similarly to above, the end of the edit must be in the
|
// Similarly to above, the end of the edit must be in the
|
||||||
// reconsidered range. However, in markup mode, we need to extend
|
// reconsidered range. However, in markup mode, we need to extend
|
||||||
// the reconsidered range by up to two nodes so that spaceing etc.
|
// the reconsidered range by up to two nodes so that spacing etc.
|
||||||
// results in the same tree.
|
// results in the same tree.
|
||||||
//
|
//
|
||||||
// Therefore, there are two cases:
|
// Therefore, there are two cases:
|
||||||
@ -400,7 +400,7 @@ fn validate(
|
|||||||
|
|
||||||
let mut right_pos = newborn_span.end;
|
let mut right_pos = newborn_span.end;
|
||||||
for child in &superseded[superseded_range.end ..] {
|
for child in &superseded[superseded_range.end ..] {
|
||||||
if child.kind().is_trivia() || child.kind() == &NodeKind::Parbreak {
|
if child.kind().is_trivia() {
|
||||||
right_pos += child.len();
|
right_pos += child.len();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -451,7 +451,6 @@ impl NodeKind {
|
|||||||
match self {
|
match self {
|
||||||
// These are all replaceable by other tokens.
|
// These are all replaceable by other tokens.
|
||||||
Self::Linebreak
|
Self::Linebreak
|
||||||
| Self::Parbreak
|
|
||||||
| Self::Text(_)
|
| Self::Text(_)
|
||||||
| Self::TextInLine(_)
|
| Self::TextInLine(_)
|
||||||
| Self::NonBreakingSpace
|
| Self::NonBreakingSpace
|
||||||
|
@ -172,11 +172,7 @@ fn markup_node(p: &mut Parser, at_start: &mut bool) {
|
|||||||
// Whitespace.
|
// Whitespace.
|
||||||
NodeKind::Space(newlines) => {
|
NodeKind::Space(newlines) => {
|
||||||
*at_start |= *newlines > 0;
|
*at_start |= *newlines > 0;
|
||||||
if *newlines < 2 {
|
|
||||||
p.eat();
|
p.eat();
|
||||||
} else {
|
|
||||||
p.convert(NodeKind::Parbreak);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,13 +176,6 @@ impl<'s> Parser<'s> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Eat the current token, but change its type.
|
|
||||||
pub fn convert(&mut self, kind: NodeKind) {
|
|
||||||
let marker = self.marker();
|
|
||||||
self.eat();
|
|
||||||
marker.convert(self, kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the current token is of the given type.
|
/// Whether the current token is of the given type.
|
||||||
pub fn at(&self, kind: &NodeKind) -> bool {
|
pub fn at(&self, kind: &NodeKind) -> bool {
|
||||||
self.peek() == Some(kind)
|
self.peek() == Some(kind)
|
||||||
|
@ -60,9 +60,9 @@ impl Markup {
|
|||||||
/// The markup nodes.
|
/// The markup nodes.
|
||||||
pub fn nodes(&self) -> impl Iterator<Item = MarkupNode> + '_ {
|
pub fn nodes(&self) -> impl Iterator<Item = MarkupNode> + '_ {
|
||||||
self.0.children().filter_map(|node| match node.kind() {
|
self.0.children().filter_map(|node| match node.kind() {
|
||||||
|
NodeKind::Space(n) if *n > 1 => Some(MarkupNode::Parbreak),
|
||||||
NodeKind::Space(_) => Some(MarkupNode::Space),
|
NodeKind::Space(_) => Some(MarkupNode::Space),
|
||||||
NodeKind::Linebreak => Some(MarkupNode::Linebreak),
|
NodeKind::Linebreak => Some(MarkupNode::Linebreak),
|
||||||
NodeKind::Parbreak => Some(MarkupNode::Parbreak),
|
|
||||||
NodeKind::Text(s) | NodeKind::TextInLine(s) => {
|
NodeKind::Text(s) | NodeKind::TextInLine(s) => {
|
||||||
Some(MarkupNode::Text(s.clone()))
|
Some(MarkupNode::Text(s.clone()))
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,6 @@ impl Category {
|
|||||||
NodeKind::Underscore => None,
|
NodeKind::Underscore => None,
|
||||||
NodeKind::Markup(_) => None,
|
NodeKind::Markup(_) => None,
|
||||||
NodeKind::Space(_) => None,
|
NodeKind::Space(_) => None,
|
||||||
NodeKind::Parbreak => None,
|
|
||||||
NodeKind::Text(_) => None,
|
NodeKind::Text(_) => None,
|
||||||
NodeKind::TextInLine(_) => None,
|
NodeKind::TextInLine(_) => None,
|
||||||
NodeKind::List => None,
|
NodeKind::List => None,
|
||||||
|
@ -589,8 +589,6 @@ pub enum NodeKind {
|
|||||||
Space(usize),
|
Space(usize),
|
||||||
/// A forced line break: `\`.
|
/// A forced line break: `\`.
|
||||||
Linebreak,
|
Linebreak,
|
||||||
/// A paragraph break: Two or more newlines.
|
|
||||||
Parbreak,
|
|
||||||
/// A consecutive non-markup string.
|
/// A consecutive non-markup string.
|
||||||
Text(EcoString),
|
Text(EcoString),
|
||||||
/// A text node that cannot appear at the beginning of a source line.
|
/// A text node that cannot appear at the beginning of a source line.
|
||||||
@ -760,7 +758,6 @@ impl NodeKind {
|
|||||||
pub fn is_at_start(&self, prev: bool) -> bool {
|
pub fn is_at_start(&self, prev: bool) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Space(n) if *n > 0 => true,
|
Self::Space(n) if *n > 0 => true,
|
||||||
Self::Parbreak => true,
|
|
||||||
Self::LineComment | Self::BlockComment => prev,
|
Self::LineComment | Self::BlockComment => prev,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
@ -771,7 +768,6 @@ impl NodeKind {
|
|||||||
match self {
|
match self {
|
||||||
Self::Markup(_)
|
Self::Markup(_)
|
||||||
| Self::Linebreak
|
| Self::Linebreak
|
||||||
| Self::Parbreak
|
|
||||||
| Self::Text(_)
|
| Self::Text(_)
|
||||||
| Self::TextInLine(_)
|
| Self::TextInLine(_)
|
||||||
| Self::NonBreakingSpace
|
| Self::NonBreakingSpace
|
||||||
@ -862,9 +858,9 @@ impl NodeKind {
|
|||||||
Self::Include => "keyword `include`",
|
Self::Include => "keyword `include`",
|
||||||
Self::From => "keyword `from`",
|
Self::From => "keyword `from`",
|
||||||
Self::Markup(_) => "markup",
|
Self::Markup(_) => "markup",
|
||||||
|
Self::Space(n) if *n > 1 => "paragraph break",
|
||||||
Self::Space(_) => "space",
|
Self::Space(_) => "space",
|
||||||
Self::Linebreak => "forced linebreak",
|
Self::Linebreak => "forced linebreak",
|
||||||
Self::Parbreak => "paragraph break",
|
|
||||||
Self::Text(_) | Self::TextInLine(_) => "text",
|
Self::Text(_) | Self::TextInLine(_) => "text",
|
||||||
Self::NonBreakingSpace => "non-breaking space",
|
Self::NonBreakingSpace => "non-breaking space",
|
||||||
Self::EnDash => "en dash",
|
Self::EnDash => "en dash",
|
||||||
@ -988,7 +984,6 @@ impl Hash for NodeKind {
|
|||||||
Self::Markup(c) => c.hash(state),
|
Self::Markup(c) => c.hash(state),
|
||||||
Self::Space(n) => n.hash(state),
|
Self::Space(n) => n.hash(state),
|
||||||
Self::Linebreak => {}
|
Self::Linebreak => {}
|
||||||
Self::Parbreak => {}
|
|
||||||
Self::Text(s) => s.hash(state),
|
Self::Text(s) => s.hash(state),
|
||||||
Self::TextInLine(s) => s.hash(state),
|
Self::TextInLine(s) => s.hash(state),
|
||||||
Self::NonBreakingSpace => {}
|
Self::NonBreakingSpace => {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user