Fix raw show rule

This commit is contained in:
Laurenz 2023-02-01 13:32:05 +01:00
parent c2bd114914
commit afa344f33d
4 changed files with 18 additions and 7 deletions

View File

@ -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)
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -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()
)

View File

@ -44,6 +44,11 @@ The keyword ```rust let```.
C
```
---
// Text show rule
#show raw: set text("Roboto")
`Roboto`
---
// Unterminated.
// Error: 2:1 expected 1 backtick