summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-02-01 13:32:05 +0100
committerLaurenz <laurmaedje@gmail.com>2023-02-01 13:32:05 +0100
commitafa344f33db80456bb3091e3863ca673d43c5db8 (patch)
treeb38b88de8603975dede856878ab598c88c3332fe
parentc2bd114914513c8ff450b9dcc67aa9b17cf275e1 (diff)
Fix raw show rule
-rw-r--r--library/src/text/raw.rs17
-rw-r--r--tests/ref/text/raw.pngbin18101 -> 19645 bytes
-rw-r--r--tests/typ/math/syntax.typ3
-rw-r--r--tests/typ/text/raw.typ5
4 files changed, 18 insertions, 7 deletions
diff --git a/library/src/text/raw.rs b/library/src/text/raw.rs
index 2f0ec79e..1051992a 100644
--- a/library/src/text/raw.rs
+++ b/library/src/text/raw.rs
@@ -2,7 +2,9 @@ use once_cell::sync::Lazy;
use syntect::highlighting as synt;
use typst::syntax::{self, LinkedNode};
-use super::{FontFamily, Hyphenate, LinebreakNode, SmartQuoteNode, TextNode};
+use super::{
+ FallbackList, FontFamily, Hyphenate, LinebreakNode, SmartQuoteNode, TextNode,
+};
use crate::layout::BlockNode;
use crate::prelude::*;
@@ -88,7 +90,7 @@ use crate::prelude::*;
/// ## Category
/// text
#[func]
-#[capable(Show, Prepare)]
+#[capable(Prepare, Show, Finalize)]
#[derive(Debug, Hash)]
pub struct RawNode {
/// The raw text.
@@ -203,13 +205,18 @@ impl Show for RawNode {
realized = BlockNode(realized).pack();
}
+ Ok(realized)
+ }
+}
+
+impl Finalize for RawNode {
+ fn finalize(&self, realized: Content) -> Content {
let mut map = StyleMap::new();
map.set(TextNode::OVERHANG, false);
map.set(TextNode::HYPHENATE, Hyphenate(Smart::Custom(false)));
map.set(SmartQuoteNode::ENABLED, false);
- map.set_family(FontFamily::new("IBM Plex Mono"), styles);
-
- Ok(realized.styled_with_map(map))
+ map.set(TextNode::FAMILY, FallbackList(vec![FontFamily::new("IBM Plex Mono")]));
+ realized.styled_with_map(map)
}
}
diff --git a/tests/ref/text/raw.png b/tests/ref/text/raw.png
index f7912051..e2fd87d0 100644
--- a/tests/ref/text/raw.png
+++ b/tests/ref/text/raw.png
Binary files differ
diff --git a/tests/typ/math/syntax.typ b/tests/typ/math/syntax.typ
index 80facfb2..8ffded29 100644
--- a/tests/typ/math/syntax.typ
+++ b/tests/typ/math/syntax.typ
@@ -1,11 +1,10 @@
#set page(width: auto)
-#set text("Latin Modern Roman")
#show <table>: it => table(
columns: 2,
inset: 8pt,
..it.text
.split("\n")
- .map(line => (text(10pt, raw(line, lang: "typ")), eval(line) + [ ]))
+ .map(line => (raw(line, lang: "typ"), text("Latin Modern Roman", eval(line))))
.flatten()
)
diff --git a/tests/typ/text/raw.typ b/tests/typ/text/raw.typ
index 96a23b66..f8731cca 100644
--- a/tests/typ/text/raw.typ
+++ b/tests/typ/text/raw.typ
@@ -45,6 +45,11 @@ The keyword ```rust let```.
```
---
+// Text show rule
+#show raw: set text("Roboto")
+`Roboto`
+
+---
// Unterminated.
// Error: 2:1 expected 1 backtick
`endless