summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/layout/hide.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-10-27 19:04:55 +0100
committerGitHub <noreply@github.com>2024-10-27 18:04:55 +0000
commitbe7cfc85d08c545abfac08098b7b33b4bd71f37e (patch)
treef4137fa2aaa57babae1f7603a9b2ed7e688f43d8 /crates/typst-library/src/layout/hide.rs
parentb8034a343831e8609aec2ec81eb7eeda57aa5d81 (diff)
Split out four new crates (#5302)
Diffstat (limited to 'crates/typst-library/src/layout/hide.rs')
-rw-r--r--crates/typst-library/src/layout/hide.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/crates/typst-library/src/layout/hide.rs b/crates/typst-library/src/layout/hide.rs
new file mode 100644
index 00000000..1b8b9bd5
--- /dev/null
+++ b/crates/typst-library/src/layout/hide.rs
@@ -0,0 +1,34 @@
+use crate::diag::SourceResult;
+use crate::engine::Engine;
+use crate::foundations::{elem, Content, Packed, Show, StyleChain};
+
+/// Hides content without affecting layout.
+///
+/// The `hide` function allows you to hide content while the layout still 'sees'
+/// it. This is useful to create whitespace that is exactly as large as some
+/// content. It may also be useful to redact content because its arguments are
+/// not included in the output.
+///
+/// # Example
+/// ```example
+/// Hello Jane \
+/// #hide[Hello] Joe
+/// ```
+#[elem(Show)]
+pub struct HideElem {
+ /// The content to hide.
+ #[required]
+ pub body: Content,
+
+ /// This style is set on the content contained in the `hide` element.
+ #[internal]
+ #[ghost]
+ pub hidden: bool,
+}
+
+impl Show for Packed<HideElem> {
+ #[typst_macros::time(name = "hide", span = self.span())]
+ fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
+ Ok(self.body().clone().styled(HideElem::set_hidden(true)))
+ }
+}