summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-10-31 13:49:10 +0100
committerLaurenz <laurmaedje@gmail.com>2022-10-31 13:49:10 +0100
commit671ce3dedd40067bb5cea84fe0739de013827053 (patch)
treea4c990fc16b514f475dfceaa98d988e92ac6cf0c /src/library
parent636bdb9e438cfe4fb075a981e0512b9a3dde3e60 (diff)
Replace `encode` with `field`
Diffstat (limited to 'src/library')
-rw-r--r--src/library/math/mod.rs4
-rw-r--r--src/library/structure/heading.rs11
-rw-r--r--src/library/structure/list.rs18
-rw-r--r--src/library/structure/reference.rs7
-rw-r--r--src/library/structure/table.rs14
-rw-r--r--src/library/text/deco.rs7
-rw-r--r--src/library/text/link.rs13
-rw-r--r--src/library/text/mod.rs14
-rw-r--r--src/library/text/raw.rs13
-rw-r--r--src/library/text/shift.rs7
10 files changed, 57 insertions, 51 deletions
diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs
index df00cb71..b23ed7cf 100644
--- a/src/library/math/mod.rs
+++ b/src/library/math/mod.rs
@@ -84,8 +84,8 @@ impl Show for MathNode {
ShowNode::new(self.clone())
}
- fn encode(&self, _: StyleChain) -> Dict {
- todo!()
+ fn field(&self, _: &str) -> Option<Value> {
+ None
}
fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> {
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs
index c967c6d7..fa96248f 100644
--- a/src/library/structure/heading.rs
+++ b/src/library/structure/heading.rs
@@ -73,12 +73,11 @@ impl Show for HeadingNode {
Self { body: self.body.unguard(sel), ..*self }.pack()
}
- fn encode(&self, styles: StyleChain) -> Dict {
- dict! {
- "level" => Value::Int(self.level.get() as i64),
- "body" => Value::Content(self.body.clone()),
- "outlined" => Value::Bool(styles.get(Self::OUTLINED)),
- "numbered" => Value::Bool(styles.get(Self::NUMBERED)),
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "level" => Some(Value::Int(self.level.get() as i64)),
+ "body" => Some(Value::Content(self.body.clone())),
+ _ => None,
}
}
diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs
index 082c98c3..8a57069e 100644
--- a/src/library/structure/list.rs
+++ b/src/library/structure/list.rs
@@ -90,16 +90,14 @@ impl<const L: ListKind> Show for ListNode<L> {
.pack()
}
- fn encode(&self, _: StyleChain) -> Dict {
- dict! {
- "tight" => Value::Bool(self.tight),
- "attached" => Value::Bool(self.attached),
- "items" => Value::Array(
- self.items
- .items()
- .map(|item| item.encode())
- .collect()
- ),
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "tight" => Some(Value::Bool(self.tight)),
+ "attached" => Some(Value::Bool(self.attached)),
+ "items" => Some(Value::Array(
+ self.items.items().map(|item| item.encode()).collect(),
+ )),
+ _ => None,
}
}
diff --git a/src/library/structure/reference.rs b/src/library/structure/reference.rs
index 0a9f4f9c..425ee518 100644
--- a/src/library/structure/reference.rs
+++ b/src/library/structure/reference.rs
@@ -16,9 +16,10 @@ impl Show for RefNode {
Self(self.0.clone()).pack()
}
- fn encode(&self, _: StyleChain) -> Dict {
- dict! {
- "label" => Value::Str(self.0.clone().into()),
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "label" => Some(Value::Str(self.0.clone().into())),
+ _ => None,
}
}
diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs
index a2f583f7..41dcd104 100644
--- a/src/library/structure/table.rs
+++ b/src/library/structure/table.rs
@@ -57,14 +57,12 @@ impl Show for TableNode {
.pack()
}
- fn encode(&self, _: StyleChain) -> Dict {
- dict! {
- "cells" => Value::Array(
- self.cells
- .iter()
- .map(|cell| Value::Content(cell.clone()))
- .collect()
- ),
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "cells" => Some(Value::Array(
+ self.cells.iter().cloned().map(Value::Content).collect(),
+ )),
+ _ => None,
}
}
diff --git a/src/library/text/deco.rs b/src/library/text/deco.rs
index 6a4905c8..ead928f6 100644
--- a/src/library/text/deco.rs
+++ b/src/library/text/deco.rs
@@ -44,8 +44,11 @@ impl<const L: DecoLine> Show for DecoNode<L> {
Self(self.0.unguard(sel)).pack()
}
- fn encode(&self, _: StyleChain) -> Dict {
- dict! { "body" => Value::Content(self.0.clone()) }
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "body" => Some(Value::Content(self.0.clone())),
+ _ => None,
+ }
}
fn realize(
diff --git a/src/library/text/link.rs b/src/library/text/link.rs
index 7c4a95ed..98a867a8 100644
--- a/src/library/text/link.rs
+++ b/src/library/text/link.rs
@@ -58,16 +58,17 @@ impl Show for LinkNode {
.pack()
}
- fn encode(&self, _: StyleChain) -> Dict {
- dict! {
- "url" => match &self.dest {
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "url" => Some(match &self.dest {
Destination::Url(url) => Value::Str(url.clone().into()),
Destination::Internal(loc) => Value::Dict(loc.encode()),
- },
- "body" => match &self.body {
+ }),
+ "body" => Some(match &self.body {
Some(body) => Value::Content(body.clone()),
None => Value::None,
- },
+ }),
+ _ => None,
}
}
diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs
index 2d302b9a..d7d2ee38 100644
--- a/src/library/text/mod.rs
+++ b/src/library/text/mod.rs
@@ -515,8 +515,11 @@ impl Show for StrongNode {
Self(self.0.unguard(sel)).pack()
}
- fn encode(&self, _: StyleChain) -> Dict {
- dict! { "body" => Value::Content(self.0.clone()) }
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "body" => Some(Value::Content(self.0.clone())),
+ _ => None,
+ }
}
fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> {
@@ -540,8 +543,11 @@ impl Show for EmphNode {
Self(self.0.unguard(sel)).pack()
}
- fn encode(&self, _: StyleChain) -> Dict {
- dict! { "body" => Value::Content(self.0.clone()) }
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "body" => Some(Value::Content(self.0.clone())),
+ _ => None,
+ }
}
fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> {
diff --git a/src/library/text/raw.rs b/src/library/text/raw.rs
index d237aa92..6d19deff 100644
--- a/src/library/text/raw.rs
+++ b/src/library/text/raw.rs
@@ -46,14 +46,11 @@ impl Show for RawNode {
Self { text: self.text.clone(), ..*self }.pack()
}
- fn encode(&self, styles: StyleChain) -> Dict {
- dict! {
- "text" => Value::Str(self.text.clone().into()),
- "block" => Value::Bool(self.block),
- "lang" => match styles.get(Self::LANG) {
- Some(lang) => Value::Str(lang.clone().into()),
- None => Value::None,
- },
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "text" => Some(Value::Str(self.text.clone().into())),
+ "block" => Some(Value::Bool(self.block)),
+ _ => None,
}
}
diff --git a/src/library/text/shift.rs b/src/library/text/shift.rs
index adad5dc0..e2a636a6 100644
--- a/src/library/text/shift.rs
+++ b/src/library/text/shift.rs
@@ -38,8 +38,11 @@ impl<const S: ScriptKind> Show for ShiftNode<S> {
Self(self.0.clone()).pack()
}
- fn encode(&self, _: StyleChain) -> Dict {
- dict! { "body" => Value::Content(self.0.clone()) }
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "body" => Some(Value::Content(self.0.clone())),
+ _ => None,
+ }
}
fn realize(