typst_library/introspection/metadata.rs
1use crate::foundations::{Value, elem};
2use crate::introspection::Locatable;
3
4/// Exposes a value to the query system without producing visible content.
5///
6/// This element can be retrieved with the [`query`] function and from the
7/// command line with
8/// [`typst query`]($reference/introspection/query/#command-line-queries). Its
9/// purpose is to expose an arbitrary value to the introspection system. To
10/// identify a metadata value among others, you can attach a [`label`] to it and
11/// query for that label.
12///
13/// The `metadata` element is especially useful for command line queries because
14/// it allows you to expose arbitrary values to the outside world.
15///
16/// ```example
17/// // Put metadata somewhere.
18/// #metadata("This is a note") <note>
19///
20/// // And find it from anywhere else.
21/// #context {
22/// query(<note>).first().value
23/// }
24/// ```
25#[elem(Locatable)]
26pub struct MetadataElem {
27 /// The value to embed into the document.
28 #[required]
29 pub value: Value,
30}