summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-13 13:52:52 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-13 13:52:52 +0200
commit11f1f0818b990be1ed4a16652b7f30bf11159237 (patch)
treeb52fc6063d8bdec3937ec384cc44ee7a616e51e4 /src
parent3e9c63d685a6ff05a72e5a07d40216ff0ac6ae32 (diff)
Pass language to raw show rule
Diffstat (limited to 'src')
-rw-r--r--src/library/math/mod.rs2
-rw-r--r--src/library/structure/heading.rs2
-rw-r--r--src/library/structure/list.rs2
-rw-r--r--src/library/structure/table.rs2
-rw-r--r--src/library/text/deco.rs2
-rw-r--r--src/library/text/link.rs2
-rw-r--r--src/library/text/mod.rs4
-rw-r--r--src/library/text/raw.rs10
-rw-r--r--src/model/recipe.rs5
-rw-r--r--src/model/show.rs6
-rw-r--r--src/model/styles.rs2
11 files changed, 22 insertions, 17 deletions
diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs
index 9709c00c..ad01f28a 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 468757ad..70589de0 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 fca7d5ce..6bcc9f3e 100644
--- a/src/library/structure/list.rs
+++ b/src/library/structure/list.rs
@@ -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),
diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs
index 304a8681..b983a7ea 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 34c70720..dedaa6e8 100644
--- a/src/library/text/deco.rs
+++ b/src/library/text/deco.rs
@@ -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()) }
}
diff --git a/src/library/text/link.rs b/src/library/text/link.rs
index 9e933529..284f0b1f 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 80b036ac..ae7024e5 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 6124359e..52cabe3d 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 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<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)))
})?
}
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<Content> {
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;
}