diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-13 14:48:19 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-13 14:48:19 +0200 |
| commit | 67e9313b9127b70b9d7dad6540853025ae90b4a5 (patch) | |
| tree | 9f060b1982534ad67ee5a0688927071aa08dd96c /src/syntax | |
| parent | 2279c26543f7edde910fd89a3f8f0710c67249db (diff) | |
Soft breaks and shy hyphens
Diffstat (limited to 'src/syntax')
| -rw-r--r-- | src/syntax/ast.rs | 8 | ||||
| -rw-r--r-- | src/syntax/highlight.rs | 3 | ||||
| -rw-r--r-- | src/syntax/mod.rs | 16 |
3 files changed, 18 insertions, 9 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index d629b1fd..b01eeb47 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -62,10 +62,11 @@ impl Markup { self.0.children().filter_map(|node| match node.kind() { NodeKind::Space(2 ..) => Some(MarkupNode::Parbreak), NodeKind::Space(_) => Some(MarkupNode::Space), - NodeKind::Linebreak => Some(MarkupNode::Linebreak), + NodeKind::Linebreak(s) => Some(MarkupNode::Linebreak(*s)), NodeKind::Text(s) => Some(MarkupNode::Text(s.clone())), NodeKind::Escape(c) => Some(MarkupNode::Text((*c).into())), NodeKind::NonBreakingSpace => Some(MarkupNode::Text('\u{00A0}'.into())), + NodeKind::Shy => Some(MarkupNode::Text('\u{00AD}'.into())), NodeKind::EnDash => Some(MarkupNode::Text('\u{2013}'.into())), NodeKind::EmDash => Some(MarkupNode::Text('\u{2014}'.into())), NodeKind::Quote(d) => Some(MarkupNode::Quote(*d)), @@ -86,8 +87,9 @@ impl Markup { pub enum MarkupNode { /// Whitespace containing less than two newlines. Space, - /// A forced line break: `\`. - Linebreak, + /// A forced line break. If soft (`\`, `true`), the preceding line can still + /// be justified, if hard (`\+`, `false`) not. + Linebreak(bool), /// A paragraph break: Two or more newlines. Parbreak, /// Plain text. diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs index 90f1c548..34e5b4a7 100644 --- a/src/syntax/highlight.rs +++ b/src/syntax/highlight.rs @@ -126,8 +126,9 @@ impl Category { _ => Some(Category::Operator), }, NodeKind::EnumNumbering(_) => Some(Category::List), - NodeKind::Linebreak => Some(Category::Shortcut), + NodeKind::Linebreak(_) => Some(Category::Shortcut), NodeKind::NonBreakingSpace => Some(Category::Shortcut), + NodeKind::Shy => Some(Category::Shortcut), NodeKind::EnDash => Some(Category::Shortcut), NodeKind::EmDash => Some(Category::Shortcut), NodeKind::Escape(_) => Some(Category::Escape), diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index f0d3cdd4..1f02217a 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -586,12 +586,15 @@ pub enum NodeKind { Markup(usize), /// One or more whitespace characters. Space(usize), - /// A forced line break: `\`. - Linebreak, /// A consecutive non-markup string. Text(EcoString), + /// A forced line break. If soft (`\`, `true`), the preceding line can still + /// be justified, if hard (`\+`, `false`) not. + Linebreak(bool), /// A non-breaking space: `~`. NonBreakingSpace, + /// A soft hyphen: `-?`. + Shy, /// An en-dash: `--`. EnDash, /// An em-dash: `---`. @@ -766,7 +769,7 @@ impl NodeKind { pub fn only_in_mode(&self) -> Option<TokenMode> { match self { Self::Markup(_) - | Self::Linebreak + | Self::Linebreak(_) | Self::Text(_) | Self::NonBreakingSpace | Self::EnDash @@ -859,9 +862,11 @@ impl NodeKind { Self::Markup(_) => "markup", Self::Space(2 ..) => "paragraph break", Self::Space(_) => "space", - Self::Linebreak => "forced linebreak", + Self::Linebreak(false) => "hard linebreak", + Self::Linebreak(true) => "soft linebreak", Self::Text(_) => "text", Self::NonBreakingSpace => "non-breaking space", + Self::Shy => "soft hyphen", Self::EnDash => "en dash", Self::EmDash => "em dash", Self::Quote(false) => "single quote", @@ -981,9 +986,10 @@ impl Hash for NodeKind { Self::From => {} Self::Markup(c) => c.hash(state), Self::Space(n) => n.hash(state), - Self::Linebreak => {} + Self::Linebreak(s) => s.hash(state), Self::Text(s) => s.hash(state), Self::NonBreakingSpace => {} + Self::Shy => {} Self::EnDash => {} Self::EmDash => {} Self::Quote(d) => d.hash(state), |
