summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/foundations/target.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-library/src/foundations/target.rs')
-rw-r--r--crates/typst-library/src/foundations/target.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/crates/typst-library/src/foundations/target.rs b/crates/typst-library/src/foundations/target.rs
new file mode 100644
index 00000000..b743ea1a
--- /dev/null
+++ b/crates/typst-library/src/foundations/target.rs
@@ -0,0 +1,38 @@
+use comemo::Tracked;
+
+use crate::diag::HintedStrResult;
+use crate::foundations::{elem, func, Cast, Context};
+
+/// The compilation target.
+#[derive(Debug, Default, Copy, Clone, PartialEq, Hash, Cast)]
+pub enum Target {
+ /// The target that is used for paged, fully laid-out content.
+ #[default]
+ Paged,
+ /// The target that is used for HTML export.
+ Html,
+}
+
+impl Target {
+ /// Whether this is the HTML target.
+ pub fn is_html(self) -> bool {
+ self == Self::Html
+ }
+}
+
+/// This element exists solely to host the `target` style chain field.
+/// It is never constructed and not visible to users.
+#[elem]
+pub struct TargetElem {
+ /// The compilation target.
+ pub target: Target,
+}
+
+/// Returns the current compilation target.
+#[func(contextual)]
+pub fn target(
+ /// The callsite context.
+ context: Tracked<Context>,
+) -> HintedStrResult<Target> {
+ Ok(TargetElem::target_in(context.styles()?))
+}