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