summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-08-29 17:26:49 +0200
committerGitHub <noreply@github.com>2020-08-29 17:26:49 +0200
commit2a6cde72726c057e2166fb4277b8fe53c398b3f9 (patch)
tree0899e1cc799fff1aedec8a19e63170a671cf969f /src/layout
parent236750c35fbad916b63774df917cbc436f1d1a8c (diff)
parentd68367f32a9e698923b554984c59f0671e27ba5f (diff)
Merge pull request #11 from typst/code-blocks
Added code blocks 🚟
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/tree.rs28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/layout/tree.rs b/src/layout/tree.rs
index adc179bc..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};
+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,6 +81,8 @@ impl<'a> TreeLayouter<'a> {
}
SyntaxNode::Raw(lines) => self.layout_raw(lines).await,
+ SyntaxNode::Code(block) => self.layout_code(block).await,
+
SyntaxNode::Call(call) => {
self.layout_call(Spanned::new(call, node.span)).await;
}
@@ -97,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(
@@ -131,6 +137,18 @@ impl<'a> TreeLayouter<'a> {
self.style.text.fallback = fallback;
}
+ async fn layout_code(&mut self, code: &Code) {
+ if code.block {
+ self.layout_parbreak();
+ }
+
+ self.layout_raw(&code.lines).await;
+
+ if code.block {
+ self.layout_parbreak()
+ }
+ }
+
async fn layout_call(&mut self, call: Spanned<&CallExpr>) {
let ctx = LayoutContext {
style: &self.style,