diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs index 9709c00c7..ad01f28a6 100644 --- a/src/library/math/mod.rs +++ b/src/library/math/mod.rs @@ -40,7 +40,7 @@ impl Show for MathNode { Self { formula: self.formula.clone(), ..*self }.pack() } - fn encode(&self) -> Dict { + fn encode(&self, _: StyleChain) -> Dict { dict! { "formula" => Value::Str(self.formula.clone()), "display" => Value::Bool(self.display) diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs index 468757ad7..70589de06 100644 --- a/src/library/structure/heading.rs +++ b/src/library/structure/heading.rs @@ -68,7 +68,7 @@ impl Show for HeadingNode { Self { body: self.body.unguard(sel), ..*self }.pack() } - fn encode(&self) -> Dict { + fn encode(&self, _: StyleChain) -> Dict { dict! { "level" => Value::Int(self.level.get() as i64), "body" => Value::Content(self.body.clone()), diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs index fca7d5ce3..6bcc9f3ea 100644 --- a/src/library/structure/list.rs +++ b/src/library/structure/list.rs @@ -86,7 +86,7 @@ impl Show for ListNode { .pack() } - fn encode(&self) -> Dict { + fn encode(&self, _: StyleChain) -> Dict { dict! { "start" => Value::Int(self.start as i64), "tight" => Value::Bool(self.tight), diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs index 304a86811..b983a7eab 100644 --- a/src/library/structure/table.rs +++ b/src/library/structure/table.rs @@ -60,7 +60,7 @@ impl Show for TableNode { .pack() } - fn encode(&self) -> Dict { + fn encode(&self, _: StyleChain) -> Dict { dict! { "cells" => Value::Array( self.cells diff --git a/src/library/text/deco.rs b/src/library/text/deco.rs index 34c707205..dedaa6e80 100644 --- a/src/library/text/deco.rs +++ b/src/library/text/deco.rs @@ -45,7 +45,7 @@ impl Show for DecoNode { Self(self.0.unguard(sel)).pack() } - fn encode(&self) -> Dict { + fn encode(&self, _: StyleChain) -> Dict { dict! { "body" => Value::Content(self.0.clone()) } } diff --git a/src/library/text/link.rs b/src/library/text/link.rs index 9e9335298..284f0b1f9 100644 --- a/src/library/text/link.rs +++ b/src/library/text/link.rs @@ -36,7 +36,7 @@ impl Show for LinkNode { .pack() } - fn encode(&self) -> Dict { + fn encode(&self, _: StyleChain) -> Dict { dict! { "url" => Value::Str(self.url.clone()), "body" => match &self.body { diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs index 80b036ac5..ae7024e59 100644 --- a/src/library/text/mod.rs +++ b/src/library/text/mod.rs @@ -524,7 +524,7 @@ impl Show for StrongNode { Self(self.0.unguard(sel)).pack() } - fn encode(&self) -> Dict { + fn encode(&self, _: StyleChain) -> Dict { dict! { "body" => Value::Content(self.0.clone()) } } @@ -549,7 +549,7 @@ impl Show for EmphNode { Self(self.0.unguard(sel)).pack() } - fn encode(&self) -> Dict { + fn encode(&self, _: StyleChain) -> Dict { dict! { "body" => Value::Content(self.0.clone()) } } diff --git a/src/library/text/raw.rs b/src/library/text/raw.rs index 6124359ec..52cabe3d7 100644 --- a/src/library/text/raw.rs +++ b/src/library/text/raw.rs @@ -52,10 +52,14 @@ impl Show for RawNode { Self { text: self.text.clone(), ..*self }.pack() } - fn encode(&self) -> Dict { + fn encode(&self, styles: StyleChain) -> Dict { dict! { - "text" => Value::Str(self.text.clone()), - "block" => Value::Bool(self.block) + "text" => Value::Str(self.text.clone()), + "block" => Value::Bool(self.block), + "lang" => match styles.get(Self::LANG) { + Some(lang) => Value::Str(lang.clone()), + None => Value::None, + }, } } diff --git a/src/model/recipe.rs b/src/model/recipe.rs index 48e7a22e1..905e035ec 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 af87d9305..ac73cb769 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 3c25971c8..928133c74 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; }