Pass language to raw show rule
This commit is contained in:
parent
3e9c63d685
commit
11f1f0818b
@ -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)
|
||||
|
@ -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()),
|
||||
|
@ -86,7 +86,7 @@ impl<const L: ListKind> Show for ListNode<L> {
|
||||
.pack()
|
||||
}
|
||||
|
||||
fn encode(&self) -> Dict {
|
||||
fn encode(&self, _: StyleChain) -> Dict {
|
||||
dict! {
|
||||
"start" => Value::Int(self.start as i64),
|
||||
"tight" => Value::Bool(self.tight),
|
||||
|
@ -60,7 +60,7 @@ impl Show for TableNode {
|
||||
.pack()
|
||||
}
|
||||
|
||||
fn encode(&self) -> Dict {
|
||||
fn encode(&self, _: StyleChain) -> Dict {
|
||||
dict! {
|
||||
"cells" => Value::Array(
|
||||
self.cells
|
||||
|
@ -45,7 +45,7 @@ impl<const L: DecoLine> Show for DecoNode<L> {
|
||||
Self(self.0.unguard(sel)).pack()
|
||||
}
|
||||
|
||||
fn encode(&self) -> Dict {
|
||||
fn encode(&self, _: StyleChain) -> Dict {
|
||||
dict! { "body" => Value::Content(self.0.clone()) }
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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()) }
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Option<Content>> {
|
||||
@ -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)))
|
||||
})?
|
||||
}
|
||||
|
@ -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<Content> {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user