diff options
| author | Martin Haug <mhaug@live.de> | 2020-08-29 13:53:59 +0200 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2020-08-29 13:53:59 +0200 |
| commit | c2b6f2dc359d3b5c5b09996b8902c09e27271b4c (patch) | |
| tree | 2c1091d455223f2f96dad87417fe679255dc8a97 /src/layout | |
| parent | 8a45ec2875a4f72cb02d574b63b5dda141da35c1 (diff) | |
Added code blocks 🚟
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/tree.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/layout/tree.rs b/src/layout/tree.rs index e500c4ba..f039d9b0 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}; +use crate::syntax::tree::{CallExpr, SyntaxNode, SyntaxTree, CodeBlockExpr}; use crate::{DynFuture, Feedback, Pass}; use super::line::{LineContext, LineLayouter}; use super::text::{layout_text, TextContext}; @@ -80,6 +80,7 @@ impl<'a> TreeLayouter<'a> { } SyntaxNode::Raw(lines) => self.layout_raw(lines).await, + SyntaxNode::CodeBlock(block) => self.layout_code(block).await, SyntaxNode::Par(par) => self.layout_par(par).await, SyntaxNode::Call(call) => { self.layout_call(Spanned::new(call, node.span)).await; @@ -128,6 +129,21 @@ 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(); + } + + self.style.text.fallback = fallback; + } + async fn layout_par(&mut self, par: &SyntaxTree) { self.layout_tree(par).await; self.layouter.add_secondary_spacing( |
