summaryrefslogtreecommitdiff
path: root/crates/typst-library/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-library/src')
-rw-r--r--crates/typst-library/src/foundations/module.rs19
-rw-r--r--crates/typst-library/src/foundations/ops.rs1
2 files changed, 16 insertions, 4 deletions
diff --git a/crates/typst-library/src/foundations/module.rs b/crates/typst-library/src/foundations/module.rs
index 55d8bab6..14eefca3 100644
--- a/crates/typst-library/src/foundations/module.rs
+++ b/crates/typst-library/src/foundations/module.rs
@@ -19,11 +19,8 @@ use crate::foundations::{repr, ty, Content, Scope, Value};
///
/// You can access definitions from the module using [field access
/// notation]($scripting/#fields) and interact with it using the [import and
-/// include syntaxes]($scripting/#modules). Alternatively, it is possible to
-/// convert a module to a dictionary, and therefore access its contents
-/// dynamically, using the [dictionary constructor]($dictionary/#constructor).
+/// include syntaxes]($scripting/#modules).
///
-/// # Example
/// ```example
/// <<< #import "utils.typ"
/// <<< #utils.add(2, 5)
@@ -34,6 +31,20 @@ use crate::foundations::{repr, ty, Content, Scope, Value};
/// >>>
/// >>> #(-3)
/// ```
+///
+/// You can check whether a definition is present in a module using the `{in}`
+/// operator, with a string on the left-hand side. This can be useful to
+/// [conditionally access]($category/foundations/std/#conditional-access)
+/// definitions in a module.
+///
+/// ```example
+/// #("table" in std) \
+/// #("nope" in std)
+/// ```
+///
+/// Alternatively, it is possible to convert a module to a dictionary, and
+/// therefore access its contents dynamically, using the [dictionary
+/// constructor]($dictionary/#constructor).
#[ty(cast)]
#[derive(Clone, Hash)]
#[allow(clippy::derived_hash_with_manual_eq)]
diff --git a/crates/typst-library/src/foundations/ops.rs b/crates/typst-library/src/foundations/ops.rs
index 6c240844..3c6a5e6c 100644
--- a/crates/typst-library/src/foundations/ops.rs
+++ b/crates/typst-library/src/foundations/ops.rs
@@ -558,6 +558,7 @@ pub fn contains(lhs: &Value, rhs: &Value) -> Option<bool> {
(Str(a), Str(b)) => Some(b.as_str().contains(a.as_str())),
(Dyn(a), Str(b)) => a.downcast::<Regex>().map(|regex| regex.is_match(b)),
(Str(a), Dict(b)) => Some(b.contains(a)),
+ (Str(a), Module(b)) => Some(b.scope().get(a).is_some()),
(a, Array(b)) => Some(b.contains(a.clone())),
_ => Option::None,