summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
Diffstat (limited to 'library')
-rw-r--r--library/Cargo.toml1
-rw-r--r--library/src/lib.rs2
-rw-r--r--library/src/text/mod.rs2
-rw-r--r--library/src/text/symbol.rs35
4 files changed, 40 insertions, 0 deletions
diff --git a/library/Cargo.toml b/library/Cargo.toml
index 92bf84a2..2410cb0c 100644
--- a/library/Cargo.toml
+++ b/library/Cargo.toml
@@ -21,6 +21,7 @@ rex = { git = "https://github.com/laurmaedje/ReX" }
roxmltree = "0.14"
rustybuzz = "0.5"
serde_json = "1"
+symmie = { git = "https://github.com/typst/symmie" }
syntect = { version = "5", default-features = false, features = ["default-syntaxes", "regex-fancy"] }
ttf-parser = "0.17"
typed-arena = "2"
diff --git a/library/src/lib.rs b/library/src/lib.rs
index 3543a672..d549c1cd 100644
--- a/library/src/lib.rs
+++ b/library/src/lib.rs
@@ -34,6 +34,7 @@ fn scope() -> Scope {
// Text.
std.def_node::<text::TextNode>("text");
std.def_node::<text::LinebreakNode>("linebreak");
+ std.def_node::<text::SymbolNode>("symbol");
std.def_node::<text::SmartQuoteNode>("smartquote");
std.def_node::<text::StrongNode>("strong");
std.def_node::<text::EmphNode>("emph");
@@ -173,6 +174,7 @@ fn items() -> LangItems {
text: |text| text::TextNode(text).pack(),
text_id: NodeId::of::<text::TextNode>(),
text_str: |content| Some(&content.to::<text::TextNode>()?.0),
+ symbol: |notation| text::SymbolNode(notation).pack(),
smart_quote: |double| text::SmartQuoteNode { double }.pack(),
parbreak: || layout::ParbreakNode.pack(),
strong: |body| text::StrongNode(body).pack(),
diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs
index 47aaba36..5466637e 100644
--- a/library/src/text/mod.rs
+++ b/library/src/text/mod.rs
@@ -6,6 +6,7 @@ mod quotes;
mod raw;
mod shaping;
mod shift;
+mod symbol;
pub use self::deco::*;
pub use self::misc::*;
@@ -13,6 +14,7 @@ pub use self::quotes::*;
pub use self::raw::*;
pub use self::shaping::*;
pub use self::shift::*;
+pub use self::symbol::*;
use std::borrow::Cow;
diff --git a/library/src/text/symbol.rs b/library/src/text/symbol.rs
new file mode 100644
index 00000000..cc12afb9
--- /dev/null
+++ b/library/src/text/symbol.rs
@@ -0,0 +1,35 @@
+use crate::prelude::*;
+use crate::text::TextNode;
+
+/// A symbol identified by symmie notation.
+#[derive(Debug, Hash)]
+pub struct SymbolNode(pub EcoString);
+
+#[node(Show)]
+impl SymbolNode {
+ fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> {
+ Ok(Self(args.expect("notation")?).pack())
+ }
+
+ fn field(&self, name: &str) -> Option<Value> {
+ match name {
+ "notation" => Some(Value::Str(self.0.clone().into())),
+ _ => None,
+ }
+ }
+}
+
+impl Show for SymbolNode {
+ fn show(&self, _: &mut Vt, this: &Content, _: StyleChain) -> SourceResult<Content> {
+ match symmie::get(&self.0) {
+ Some(c) => Ok(TextNode::packed(c)),
+ None => {
+ if let Some(span) = this.span() {
+ bail!(span, "unknown symbol");
+ }
+
+ Ok(Content::empty())
+ }
+ }
+ }
+}