diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-09-30 18:59:33 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-09-30 18:59:33 +0200 |
| commit | 4077a7c11ea19b1b6b6b6fe3014b9018846cf21b (patch) | |
| tree | 70e4c891c2c660b4136890cebbae7c375fe36c05 /src/layout | |
| parent | 7cc279f7ae122f4c40592004dde89792c636b3c8 (diff) | |
Refactor raw blocks 💱
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/tree.rs | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 82a91131..24a00367 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -5,7 +5,7 @@ use super::text::{layout_text, TextContext}; use super::*; use crate::style::LayoutStyle; use crate::syntax::{ - CallExpr, Code, Decoration, Heading, Span, SpanWith, Spanned, SyntaxNode, SyntaxTree, + CallExpr, Decoration, Heading, Raw, Span, SpanWith, Spanned, SyntaxNode, SyntaxTree, }; use crate::{DynFuture, Feedback, Pass}; @@ -83,8 +83,7 @@ impl<'a> TreeLayouter<'a> { SyntaxNode::Heading(heading) => self.layout_heading(heading).await, - SyntaxNode::Raw(lines) => self.layout_raw(lines).await, - SyntaxNode::Code(block) => self.layout_code(block).await, + SyntaxNode::Raw(raw) => self.layout_raw(raw).await, SyntaxNode::Call(call) => { self.layout_call(call.span_with(node.span)).await; @@ -128,14 +127,18 @@ impl<'a> TreeLayouter<'a> { self.style.text = style; } - async fn layout_raw(&mut self, lines: &[String]) { + async fn layout_raw(&mut self, raw: &Raw) { + if !raw.inline { + self.layout_parbreak(); + } + // TODO: Make this more efficient. let fallback = self.style.text.fallback.clone(); self.style.text.fallback.list.insert(0, "monospace".to_string()); self.style.text.fallback.flatten(); let mut first = true; - for line in lines { + for line in &raw.lines { if !first { self.layouter.finish_line(); } @@ -144,18 +147,10 @@ impl<'a> TreeLayouter<'a> { } self.style.text.fallback = fallback; - } - async fn layout_code(&mut self, code: &Code) { - if code.block { + if !raw.inline { self.layout_parbreak(); } - - self.layout_raw(&code.lines).await; - - if code.block { - self.layout_parbreak() - } } async fn layout_call(&mut self, call: Spanned<&CallExpr>) { |
