mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Make show rule fallible again
This commit is contained in:
parent
1bb05677fa
commit
1d324235bd
@ -71,12 +71,12 @@ impl Prepare for HeadingNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Show for HeadingNode {
|
impl Show for HeadingNode {
|
||||||
fn show(&self, _: &mut Vt, this: &Content, _: StyleChain) -> Content {
|
fn show(&self, _: &mut Vt, this: &Content, _: StyleChain) -> SourceResult<Content> {
|
||||||
let mut realized = self.body.clone();
|
let mut realized = self.body.clone();
|
||||||
if let Some(Value::Str(numbering)) = this.field("numbers") {
|
if let Some(Value::Str(numbering)) = this.field("numbers") {
|
||||||
realized = TextNode::packed(numbering) + SpaceNode.pack() + realized;
|
realized = TextNode::packed(numbering) + SpaceNode.pack() + realized;
|
||||||
}
|
}
|
||||||
BlockNode(realized).pack()
|
Ok(BlockNode(realized).pack())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ impl MathNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Show for MathNode {
|
impl Show for MathNode {
|
||||||
fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> Content {
|
fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> SourceResult<Content> {
|
||||||
let mut map = StyleMap::new();
|
let mut map = StyleMap::new();
|
||||||
map.set_family(FontFamily::new("NewComputerModernMath"), styles);
|
map.set_family(FontFamily::new("NewComputerModernMath"), styles);
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ impl Show for MathNode {
|
|||||||
realized = realized.aligned(Axes::with_x(Some(Align::Center.into())))
|
realized = realized.aligned(Axes::with_x(Some(Align::Center.into())))
|
||||||
}
|
}
|
||||||
|
|
||||||
realized
|
Ok(realized)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ impl LinkNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Show for LinkNode {
|
impl Show for LinkNode {
|
||||||
fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> Content {
|
fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> SourceResult<Content> {
|
||||||
self.body.clone()
|
Ok(self.body.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,12 @@ impl Prepare for OutlineNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Show for OutlineNode {
|
impl Show for OutlineNode {
|
||||||
fn show(&self, vt: &mut Vt, _: &Content, styles: StyleChain) -> Content {
|
fn show(
|
||||||
|
&self,
|
||||||
|
vt: &mut Vt,
|
||||||
|
_: &Content,
|
||||||
|
styles: StyleChain,
|
||||||
|
) -> SourceResult<Content> {
|
||||||
let mut seq = vec![];
|
let mut seq = vec![];
|
||||||
if let Some(title) = styles.get(Self::TITLE) {
|
if let Some(title) = styles.get(Self::TITLE) {
|
||||||
let body = title.clone().unwrap_or_else(|| {
|
let body = title.clone().unwrap_or_else(|| {
|
||||||
@ -137,6 +142,6 @@ impl Show for OutlineNode {
|
|||||||
ancestors.push(node);
|
ancestors.push(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockNode(Content::sequence(seq)).pack()
|
Ok(BlockNode(Content::sequence(seq)).pack())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ impl RefNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Show for RefNode {
|
impl Show for RefNode {
|
||||||
fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> Content {
|
fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> SourceResult<Content> {
|
||||||
TextNode::packed(format_eco!("@{}", self.0))
|
Ok(TextNode::packed(format_eco!("@{}", self.0)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,8 @@ impl<const L: DecoLine> DecoNode<L> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<const L: DecoLine> Show for DecoNode<L> {
|
impl<const L: DecoLine> Show for DecoNode<L> {
|
||||||
fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> Content {
|
fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> SourceResult<Content> {
|
||||||
self.0.clone().styled(
|
Ok(self.0.clone().styled(
|
||||||
TextNode::DECO,
|
TextNode::DECO,
|
||||||
Decoration {
|
Decoration {
|
||||||
line: L,
|
line: L,
|
||||||
@ -57,7 +57,7 @@ impl<const L: DecoLine> Show for DecoNode<L> {
|
|||||||
extent: styles.get(Self::EXTENT),
|
extent: styles.get(Self::EXTENT),
|
||||||
evade: styles.get(Self::EVADE),
|
evade: styles.get(Self::EVADE),
|
||||||
},
|
},
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,8 +62,8 @@ impl StrongNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Show for StrongNode {
|
impl Show for StrongNode {
|
||||||
fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> Content {
|
fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> SourceResult<Content> {
|
||||||
self.0.clone().styled(TextNode::DELTA, Delta(styles.get(Self::DELTA)))
|
Ok(self.0.clone().styled(TextNode::DELTA, Delta(styles.get(Self::DELTA))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,8 +104,8 @@ impl EmphNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Show for EmphNode {
|
impl Show for EmphNode {
|
||||||
fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> Content {
|
fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> SourceResult<Content> {
|
||||||
self.0.clone().styled(TextNode::EMPH, Toggle)
|
Ok(self.0.clone().styled(TextNode::EMPH, Toggle))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ impl Prepare for RawNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Show for RawNode {
|
impl Show for RawNode {
|
||||||
fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> Content {
|
fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> SourceResult<Content> {
|
||||||
let lang = styles.get(Self::LANG).as_ref().map(|s| s.to_lowercase());
|
let lang = styles.get(Self::LANG).as_ref().map(|s| s.to_lowercase());
|
||||||
let foreground = THEME
|
let foreground = THEME
|
||||||
.settings
|
.settings
|
||||||
@ -109,7 +109,7 @@ impl Show for RawNode {
|
|||||||
map.set(TextNode::SMART_QUOTES, false);
|
map.set(TextNode::SMART_QUOTES, false);
|
||||||
map.set_family(FontFamily::new("IBM Plex Mono"), styles);
|
map.set_family(FontFamily::new("IBM Plex Mono"), styles);
|
||||||
|
|
||||||
realized.styled_with_map(map)
|
Ok(realized.styled_with_map(map))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,12 @@ impl<const S: ShiftKind> ShiftNode<S> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<const S: ShiftKind> Show for ShiftNode<S> {
|
impl<const S: ShiftKind> Show for ShiftNode<S> {
|
||||||
fn show(&self, vt: &mut Vt, _: &Content, styles: StyleChain) -> Content {
|
fn show(
|
||||||
|
&self,
|
||||||
|
vt: &mut Vt,
|
||||||
|
_: &Content,
|
||||||
|
styles: StyleChain,
|
||||||
|
) -> SourceResult<Content> {
|
||||||
let mut transformed = None;
|
let mut transformed = None;
|
||||||
if styles.get(Self::TYPOGRAPHIC) {
|
if styles.get(Self::TYPOGRAPHIC) {
|
||||||
if let Some(text) = search_text(&self.0, S) {
|
if let Some(text) = search_text(&self.0, S) {
|
||||||
@ -53,12 +58,12 @@ impl<const S: ShiftKind> Show for ShiftNode<S> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
transformed.unwrap_or_else(|| {
|
Ok(transformed.unwrap_or_else(|| {
|
||||||
let mut map = StyleMap::new();
|
let mut map = StyleMap::new();
|
||||||
map.set(TextNode::BASELINE, styles.get(Self::BASELINE));
|
map.set(TextNode::BASELINE, styles.get(Self::BASELINE));
|
||||||
map.set(TextNode::SIZE, styles.get(Self::SIZE));
|
map.set(TextNode::SIZE, styles.get(Self::SIZE));
|
||||||
self.0.clone().styled_with_map(map)
|
self.0.clone().styled_with_map(map)
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ pub fn realize(
|
|||||||
if let Some(showable) = target.with::<dyn Show>() {
|
if let Some(showable) = target.with::<dyn Show>() {
|
||||||
let guard = Guard::Base(target.id());
|
let guard = Guard::Base(target.id());
|
||||||
if realized.is_none() && !target.is_guarded(guard) {
|
if realized.is_none() && !target.is_guarded(guard) {
|
||||||
realized = Some(showable.show(vt, target, styles));
|
realized = Some(showable.show(vt, target, styles)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +139,12 @@ pub trait Prepare {
|
|||||||
#[capability]
|
#[capability]
|
||||||
pub trait Show {
|
pub trait Show {
|
||||||
/// Execute the base recipe for this node.
|
/// Execute the base recipe for this node.
|
||||||
fn show(&self, vt: &mut Vt, this: &Content, styles: StyleChain) -> Content;
|
fn show(
|
||||||
|
&self,
|
||||||
|
vt: &mut Vt,
|
||||||
|
this: &Content,
|
||||||
|
styles: StyleChain,
|
||||||
|
) -> SourceResult<Content>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Post-process a node after it was realized.
|
/// Post-process a node after it was realized.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user