summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-03 15:58:15 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-03 15:58:15 +0200
commitd59109e8fffa1d0b03234329e12f5d3e578804e8 (patch)
treefe7453da6f2ae327993e5ca6436ddc6a448a2c41 /src/library
parentf77f1f61bf05ae506689be3c40252c5807276280 (diff)
Support recursive show rules
Diffstat (limited to 'src/library')
-rw-r--r--src/library/math/mod.rs4
-rw-r--r--src/library/prelude.rs4
-rw-r--r--src/library/structure/heading.rs4
-rw-r--r--src/library/structure/list.rs13
-rw-r--r--src/library/structure/table.rs9
-rw-r--r--src/library/text/deco.rs6
-rw-r--r--src/library/text/link.rs8
-rw-r--r--src/library/text/mod.rs8
-rw-r--r--src/library/text/par.rs5
-rw-r--r--src/library/text/raw.rs4
10 files changed, 60 insertions, 5 deletions
diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs
index 7b4998ca..9709c00c 100644
--- a/src/library/math/mod.rs
+++ b/src/library/math/mod.rs
@@ -36,6 +36,10 @@ impl MathNode {
}
impl Show for MathNode {
+ fn unguard(&self, _: Selector) -> ShowNode {
+ Self { formula: self.formula.clone(), ..*self }.pack()
+ }
+
fn encode(&self) -> Dict {
dict! {
"formula" => Value::Str(self.formula.clone()),
diff --git a/src/library/prelude.rs b/src/library/prelude.rs
index 584b2ab2..99bff51a 100644
--- a/src/library/prelude.rs
+++ b/src/library/prelude.rs
@@ -15,8 +15,8 @@ pub use crate::eval::{
pub use crate::frame::*;
pub use crate::geom::*;
pub use crate::model::{
- Content, Fold, Key, Layout, LayoutNode, Regions, Resolve, Show, ShowNode, StyleChain,
- StyleMap, StyleVec,
+ Content, Fold, Key, Layout, LayoutNode, Regions, Resolve, Selector, Show, ShowNode,
+ StyleChain, StyleMap, StyleVec,
};
pub use crate::syntax::{Span, Spanned};
pub use crate::util::{EcoString, OptionExt};
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs
index 4f6c54f3..468757ad 100644
--- a/src/library/structure/heading.rs
+++ b/src/library/structure/heading.rs
@@ -64,6 +64,10 @@ impl HeadingNode {
}
impl Show for HeadingNode {
+ fn unguard(&self, sel: Selector) -> ShowNode {
+ Self { body: self.body.unguard(sel), ..*self }.pack()
+ }
+
fn encode(&self) -> Dict {
dict! {
"level" => Value::Int(self.level.get() as i64),
diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs
index 4356ffb4..fca7d5ce 100644
--- a/src/library/structure/list.rs
+++ b/src/library/structure/list.rs
@@ -75,6 +75,17 @@ impl<const L: ListKind> ListNode<L> {
}
impl<const L: ListKind> Show for ListNode<L> {
+ fn unguard(&self, sel: Selector) -> ShowNode {
+ Self {
+ items: self.items.map(|item| ListItem {
+ body: Box::new(item.body.unguard(sel)),
+ ..*item
+ }),
+ ..*self
+ }
+ .pack()
+ }
+
fn encode(&self) -> Dict {
dict! {
"start" => Value::Int(self.start as i64),
@@ -83,7 +94,7 @@ impl<const L: ListKind> Show for ListNode<L> {
"items" => Value::Array(
self.items
.items()
- .map(|item| Value::Content((*item.body).clone()))
+ .map(|item| Value::Content(item.body.as_ref().clone()))
.collect()
),
}
diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs
index 7b3f2ac5..304a8681 100644
--- a/src/library/structure/table.rs
+++ b/src/library/structure/table.rs
@@ -51,6 +51,15 @@ impl TableNode {
}
impl Show for TableNode {
+ fn unguard(&self, sel: Selector) -> ShowNode {
+ Self {
+ tracks: self.tracks.clone(),
+ gutter: self.gutter.clone(),
+ cells: self.cells.iter().map(|cell| cell.unguard(sel)).collect(),
+ }
+ .pack()
+ }
+
fn encode(&self) -> Dict {
dict! {
"cells" => Value::Array(
diff --git a/src/library/text/deco.rs b/src/library/text/deco.rs
index 70040f9c..34c70720 100644
--- a/src/library/text/deco.rs
+++ b/src/library/text/deco.rs
@@ -36,11 +36,15 @@ impl<const L: DecoLine> DecoNode<L> {
pub const EVADE: bool = true;
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
- Ok(Content::show(Self(args.expect::<Content>("body")?)))
+ Ok(Content::show(Self(args.expect("body")?)))
}
}
impl<const L: DecoLine> Show for DecoNode<L> {
+ fn unguard(&self, sel: Selector) -> ShowNode {
+ Self(self.0.unguard(sel)).pack()
+ }
+
fn encode(&self) -> Dict {
dict! { "body" => Value::Content(self.0.clone()) }
}
diff --git a/src/library/text/link.rs b/src/library/text/link.rs
index 710fbc47..423bcbfb 100644
--- a/src/library/text/link.rs
+++ b/src/library/text/link.rs
@@ -28,6 +28,14 @@ impl LinkNode {
}
impl Show for LinkNode {
+ fn unguard(&self, sel: Selector) -> ShowNode {
+ Self {
+ url: self.url.clone(),
+ body: self.body.as_ref().map(|body| body.unguard(sel)),
+ }
+ .pack()
+ }
+
fn encode(&self) -> Dict {
dict! {
"url" => Value::Str(self.url.clone()),
diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs
index ecc0c546..df00d87a 100644
--- a/src/library/text/mod.rs
+++ b/src/library/text/mod.rs
@@ -463,6 +463,10 @@ impl StrongNode {
}
impl Show for StrongNode {
+ fn unguard(&self, sel: Selector) -> ShowNode {
+ Self(self.0.unguard(sel)).pack()
+ }
+
fn encode(&self) -> Dict {
dict! { "body" => Value::Content(self.0.clone()) }
}
@@ -484,6 +488,10 @@ impl EmphNode {
}
impl Show for EmphNode {
+ fn unguard(&self, sel: Selector) -> ShowNode {
+ Self(self.0.unguard(sel)).pack()
+ }
+
fn encode(&self) -> Dict {
dict! { "body" => Value::Content(self.0.clone()) }
}
diff --git a/src/library/text/par.rs b/src/library/text/par.rs
index 669d07ba..6c274e7e 100644
--- a/src/library/text/par.rs
+++ b/src/library/text/par.rs
@@ -618,7 +618,10 @@ fn shared_get<'a, K: Key<'a>>(
children: &StyleVec<ParChild>,
key: K,
) -> Option<K::Output> {
- children.maps().all(|map| !map.contains(key)).then(|| styles.get(key))
+ children
+ .styles()
+ .all(|map| !map.contains(key))
+ .then(|| styles.get(key))
}
/// Find suitable linebreaks.
diff --git a/src/library/text/raw.rs b/src/library/text/raw.rs
index ee6c6356..c711aa16 100644
--- a/src/library/text/raw.rs
+++ b/src/library/text/raw.rs
@@ -51,6 +51,10 @@ impl RawNode {
}
impl Show for RawNode {
+ fn unguard(&self, _: Selector) -> ShowNode {
+ Self { text: self.text.clone(), ..*self }.pack()
+ }
+
fn encode(&self) -> Dict {
dict! {
"text" => Value::Str(self.text.clone()),