mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
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()
|
Self { formula: self.formula.clone(), ..*self }.pack()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode(&self) -> Dict {
|
fn encode(&self, _: StyleChain) -> Dict {
|
||||||
dict! {
|
dict! {
|
||||||
"formula" => Value::Str(self.formula.clone()),
|
"formula" => Value::Str(self.formula.clone()),
|
||||||
"display" => Value::Bool(self.display)
|
"display" => Value::Bool(self.display)
|
||||||
|
@ -68,7 +68,7 @@ impl Show for HeadingNode {
|
|||||||
Self { body: self.body.unguard(sel), ..*self }.pack()
|
Self { body: self.body.unguard(sel), ..*self }.pack()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode(&self) -> Dict {
|
fn encode(&self, _: StyleChain) -> Dict {
|
||||||
dict! {
|
dict! {
|
||||||
"level" => Value::Int(self.level.get() as i64),
|
"level" => Value::Int(self.level.get() as i64),
|
||||||
"body" => Value::Content(self.body.clone()),
|
"body" => Value::Content(self.body.clone()),
|
||||||
|
@ -86,7 +86,7 @@ impl<const L: ListKind> Show for ListNode<L> {
|
|||||||
.pack()
|
.pack()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode(&self) -> Dict {
|
fn encode(&self, _: StyleChain) -> Dict {
|
||||||
dict! {
|
dict! {
|
||||||
"start" => Value::Int(self.start as i64),
|
"start" => Value::Int(self.start as i64),
|
||||||
"tight" => Value::Bool(self.tight),
|
"tight" => Value::Bool(self.tight),
|
||||||
|
@ -60,7 +60,7 @@ impl Show for TableNode {
|
|||||||
.pack()
|
.pack()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode(&self) -> Dict {
|
fn encode(&self, _: StyleChain) -> Dict {
|
||||||
dict! {
|
dict! {
|
||||||
"cells" => Value::Array(
|
"cells" => Value::Array(
|
||||||
self.cells
|
self.cells
|
||||||
|
@ -45,7 +45,7 @@ impl<const L: DecoLine> Show for DecoNode<L> {
|
|||||||
Self(self.0.unguard(sel)).pack()
|
Self(self.0.unguard(sel)).pack()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode(&self) -> Dict {
|
fn encode(&self, _: StyleChain) -> Dict {
|
||||||
dict! { "body" => Value::Content(self.0.clone()) }
|
dict! { "body" => Value::Content(self.0.clone()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ impl Show for LinkNode {
|
|||||||
.pack()
|
.pack()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode(&self) -> Dict {
|
fn encode(&self, _: StyleChain) -> Dict {
|
||||||
dict! {
|
dict! {
|
||||||
"url" => Value::Str(self.url.clone()),
|
"url" => Value::Str(self.url.clone()),
|
||||||
"body" => match &self.body {
|
"body" => match &self.body {
|
||||||
|
@ -524,7 +524,7 @@ impl Show for StrongNode {
|
|||||||
Self(self.0.unguard(sel)).pack()
|
Self(self.0.unguard(sel)).pack()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode(&self) -> Dict {
|
fn encode(&self, _: StyleChain) -> Dict {
|
||||||
dict! { "body" => Value::Content(self.0.clone()) }
|
dict! { "body" => Value::Content(self.0.clone()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -549,7 +549,7 @@ impl Show for EmphNode {
|
|||||||
Self(self.0.unguard(sel)).pack()
|
Self(self.0.unguard(sel)).pack()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode(&self) -> Dict {
|
fn encode(&self, _: StyleChain) -> Dict {
|
||||||
dict! { "body" => Value::Content(self.0.clone()) }
|
dict! { "body" => Value::Content(self.0.clone()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,10 +52,14 @@ impl Show for RawNode {
|
|||||||
Self { text: self.text.clone(), ..*self }.pack()
|
Self { text: self.text.clone(), ..*self }.pack()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode(&self) -> Dict {
|
fn encode(&self, styles: StyleChain) -> Dict {
|
||||||
dict! {
|
dict! {
|
||||||
"text" => Value::Str(self.text.clone()),
|
"text" => Value::Str(self.text.clone()),
|
||||||
"block" => Value::Bool(self.block)
|
"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 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::diag::{At, TypResult};
|
||||||
use crate::eval::{Args, Func, Regex, Value};
|
use crate::eval::{Args, Func, Regex, Value};
|
||||||
use crate::library::structure::{EnumNode, ListNode};
|
use crate::library::structure::{EnumNode, ListNode};
|
||||||
@ -32,6 +32,7 @@ impl Recipe {
|
|||||||
pub fn apply(
|
pub fn apply(
|
||||||
&self,
|
&self,
|
||||||
ctx: &mut Context,
|
ctx: &mut Context,
|
||||||
|
styles: StyleChain,
|
||||||
sel: Selector,
|
sel: Selector,
|
||||||
target: Target,
|
target: Target,
|
||||||
) -> TypResult<Option<Content>> {
|
) -> TypResult<Option<Content>> {
|
||||||
@ -39,7 +40,7 @@ impl Recipe {
|
|||||||
(Target::Node(node), &Pattern::Node(id)) if node.id() == id => {
|
(Target::Node(node), &Pattern::Node(id)) if node.id() == id => {
|
||||||
let node = node.unguard(sel);
|
let node = node.unguard(sel);
|
||||||
self.call(ctx, || {
|
self.call(ctx, || {
|
||||||
let dict = node.encode();
|
let dict = node.encode(styles);
|
||||||
Value::Content(Content::Show(node, Some(dict)))
|
Value::Content(Content::Show(node, Some(dict)))
|
||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ pub trait Show: 'static {
|
|||||||
fn unguard(&self, sel: Selector) -> ShowNode;
|
fn unguard(&self, sel: Selector) -> ShowNode;
|
||||||
|
|
||||||
/// Encode this node into a dictionary.
|
/// 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
|
/// The base recipe for this node that is executed if there is no
|
||||||
/// user-defined show rule.
|
/// user-defined show rule.
|
||||||
@ -70,8 +70,8 @@ impl Show for ShowNode {
|
|||||||
self.0.unguard(sel)
|
self.0.unguard(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode(&self) -> Dict {
|
fn encode(&self, styles: StyleChain) -> Dict {
|
||||||
self.0.encode()
|
self.0.encode(styles)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn realize(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> {
|
fn realize(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> {
|
||||||
|
@ -306,7 +306,7 @@ impl<'a> StyleChain<'a> {
|
|||||||
let sel = Selector::Nth(n);
|
let sel = Selector::Nth(n);
|
||||||
if self.guarded(sel) {
|
if self.guarded(sel) {
|
||||||
guarded = true;
|
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);
|
realized = Some(content);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user