diff options
| author | Martin Haug <mhaug@live.de> | 2020-08-29 17:20:04 +0200 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2020-08-29 17:20:04 +0200 |
| commit | d68367f32a9e698923b554984c59f0671e27ba5f (patch) | |
| tree | 0899e1cc799fff1aedec8a19e63170a671cf969f /src/layout/tree.rs | |
| parent | 1eb584e256a3ce780029c7ab55c9e5891d05df3a (diff) | |
Newlines are complicated, y'all 😱
Co-authored-by: laurmaedje@outlook.de <laurmaedje@outlook.de>
Diffstat (limited to 'src/layout/tree.rs')
| -rw-r--r-- | src/layout/tree.rs | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 714cfe27..16a2930a 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -3,7 +3,7 @@ use crate::style::LayoutStyle; use crate::syntax::decoration::Decoration; use crate::syntax::span::{Span, Spanned}; -use crate::syntax::tree::{CallExpr, SyntaxNode, SyntaxTree, CodeBlockExpr}; +use crate::syntax::tree::{CallExpr, SyntaxNode, SyntaxTree, Code}; use crate::{DynFuture, Feedback, Pass}; use super::line::{LineContext, LineLayouter}; use super::text::{layout_text, TextContext}; @@ -63,10 +63,7 @@ impl<'a> TreeLayouter<'a> { match &node.v { SyntaxNode::Spacing => self.layout_space(), SyntaxNode::Linebreak => self.layouter.finish_line(), - SyntaxNode::Parbreak => self.layouter.add_secondary_spacing( - self.style.text.paragraph_spacing(), - SpacingKind::PARAGRAPH, - ), + SyntaxNode::Parbreak => self.layout_parbreak(), SyntaxNode::ToggleItalic => { self.style.text.italic = !self.style.text.italic; @@ -84,7 +81,7 @@ impl<'a> TreeLayouter<'a> { } SyntaxNode::Raw(lines) => self.layout_raw(lines).await, - SyntaxNode::CodeBlock(block) => self.layout_code(block).await, + SyntaxNode::Code(block) => self.layout_code(block).await, SyntaxNode::Call(call) => { self.layout_call(Spanned::new(call, node.span)).await; @@ -99,6 +96,13 @@ impl<'a> TreeLayouter<'a> { ); } + fn layout_parbreak(&mut self) { + self.layouter.add_secondary_spacing( + self.style.text.paragraph_spacing(), + SpacingKind::PARAGRAPH, + ); + } + async fn layout_text(&mut self, text: &str) { self.layouter.add( layout_text( @@ -133,19 +137,16 @@ impl<'a> TreeLayouter<'a> { self.style.text.fallback = fallback; } - async fn layout_code(&mut self, block: &CodeBlockExpr) { - let fallback = self.style.text.fallback.clone(); - self.style.text.fallback - .list_mut() - .insert(0, "monospace".to_string()); - self.style.text.fallback.flatten(); - - for line in &block.raw { - self.layout_text(line).await; - self.layouter.finish_line(); + async fn layout_code(&mut self, code: &Code) { + if code.block { + self.layout_parbreak(); } - self.style.text.fallback = fallback; + self.layout_raw(&code.lines).await; + + if code.block { + self.layout_parbreak() + } } async fn layout_call(&mut self, call: Spanned<&CallExpr>) { |
