From 11f1f0818b990be1ed4a16652b7f30bf11159237 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 13 May 2022 13:52:52 +0200 Subject: Pass language to raw show rule --- src/model/recipe.rs | 5 +++-- src/model/show.rs | 6 +++--- src/model/styles.rs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/model') diff --git a/src/model/recipe.rs b/src/model/recipe.rs index 48e7a22e..905e035e 100644 --- a/src/model/recipe.rs +++ b/src/model/recipe.rs @@ -1,6 +1,6 @@ use std::fmt::{self, Debug, Formatter}; -use super::{Content, Interruption, NodeId, Show, ShowNode, StyleEntry}; +use super::{Content, Interruption, NodeId, Show, ShowNode, StyleChain, StyleEntry}; use crate::diag::{At, TypResult}; use crate::eval::{Args, Func, Regex, Value}; use crate::library::structure::{EnumNode, ListNode}; @@ -32,6 +32,7 @@ impl Recipe { pub fn apply( &self, ctx: &mut Context, + styles: StyleChain, sel: Selector, target: Target, ) -> TypResult> { @@ -39,7 +40,7 @@ impl Recipe { (Target::Node(node), &Pattern::Node(id)) if node.id() == id => { let node = node.unguard(sel); self.call(ctx, || { - let dict = node.encode(); + let dict = node.encode(styles); Value::Content(Content::Show(node, Some(dict))) })? } diff --git a/src/model/show.rs b/src/model/show.rs index af87d930..ac73cb76 100644 --- a/src/model/show.rs +++ b/src/model/show.rs @@ -14,7 +14,7 @@ pub trait Show: 'static { fn unguard(&self, sel: Selector) -> ShowNode; /// Encode this node into a dictionary. - fn encode(&self) -> Dict; + fn encode(&self, styles: StyleChain) -> Dict; /// The base recipe for this node that is executed if there is no /// user-defined show rule. @@ -70,8 +70,8 @@ impl Show for ShowNode { self.0.unguard(sel) } - fn encode(&self) -> Dict { - self.0.encode() + fn encode(&self, styles: StyleChain) -> Dict { + self.0.encode(styles) } fn realize(&self, ctx: &mut Context, styles: StyleChain) -> TypResult { diff --git a/src/model/styles.rs b/src/model/styles.rs index 3c25971c..928133c7 100644 --- a/src/model/styles.rs +++ b/src/model/styles.rs @@ -306,7 +306,7 @@ impl<'a> StyleChain<'a> { let sel = Selector::Nth(n); if self.guarded(sel) { guarded = true; - } else if let Some(content) = recipe.apply(ctx, sel, target)? { + } else if let Some(content) = recipe.apply(ctx, self, sel, target)? { realized = Some(content); break; } -- cgit v1.2.3