diff --git a/crates/typst/src/foundations/content.rs b/crates/typst/src/foundations/content.rs index 582fd9c50..16ab0c04f 100644 --- a/crates/typst/src/foundations/content.rs +++ b/crates/typst/src/foundations/content.rs @@ -159,11 +159,6 @@ impl Content { self.inner.guards.contains(&guard) } - /// Whether no show rule was executed for this content so far. - pub fn is_pristine(&self) -> bool { - self.inner.guards.is_empty() - } - /// Whether this content has already been prepared. pub fn is_prepared(&self) -> bool { self.inner.prepared diff --git a/crates/typst/src/foundations/element.rs b/crates/typst/src/foundations/element.rs index 665aa8ef7..dfe8ddb58 100644 --- a/crates/typst/src/foundations/element.rs +++ b/crates/typst/src/foundations/element.rs @@ -331,9 +331,4 @@ pub enum Behaviour { /// Guards content against being affected by the same show rule multiple times. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum Guard { - /// The nth recipe from the top of the chain. - Nth(usize), - /// The [base recipe](Show) for a kind of element. - Base(Element), -} +pub struct Guard(pub usize); diff --git a/crates/typst/src/math/equation.rs b/crates/typst/src/math/equation.rs index 33f8a23af..227fdc3fa 100644 --- a/crates/typst/src/math/equation.rs +++ b/crates/typst/src/math/equation.rs @@ -3,8 +3,8 @@ use std::num::NonZeroUsize; use crate::diag::{bail, SourceResult}; use crate::engine::Engine; use crate::foundations::{ - elem, Content, Finalize, Guard, NativeElement, Packed, Resolve, Show, Smart, - StyleChain, Synthesize, + elem, Content, Finalize, NativeElement, Packed, Resolve, Smart, StyleChain, + Synthesize, }; use crate::introspection::{Count, Counter, CounterUpdate, Locatable}; use crate::layout::{ @@ -47,7 +47,6 @@ use crate::World; #[elem( Locatable, Synthesize, - Show, Finalize, LayoutSingle, LayoutMath, @@ -120,17 +119,6 @@ impl Synthesize for Packed { } } -impl Show for Packed { - #[typst_macros::time(name = "math.equation", span = self.span())] - fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult { - let mut realized = self.clone().pack().guarded(Guard::Base(EquationElem::elem())); - if self.block(styles) { - realized = AlignElem::new(realized).pack().spanned(self.span()); - } - Ok(realized) - } -} - impl Finalize for Packed { fn finalize(&self, realized: Content, style: StyleChain) -> Content { let mut realized = realized; diff --git a/crates/typst/src/realize/mod.rs b/crates/typst/src/realize/mod.rs index ff191d80f..cd40ac866 100644 --- a/crates/typst/src/realize/mod.rs +++ b/crates/typst/src/realize/mod.rs @@ -71,11 +71,7 @@ pub fn realize_block<'a>( /// Whether the target is affected by show rules in the given style chain. pub fn applicable(target: &Content, styles: StyleChain) -> bool { - if target.needs_preparation() { - return true; - } - - if target.can::() && target.is_pristine() { + if target.needs_preparation() || target.can::() { return true; } @@ -84,7 +80,7 @@ pub fn applicable(target: &Content, styles: StyleChain) -> bool { // Find out whether any recipe matches and is unguarded. for recipe in styles.recipes() { - if recipe.applicable(target) && !target.is_guarded(Guard::Nth(n)) { + if !target.is_guarded(Guard(n)) && recipe.applicable(target) { return true; } n -= 1; @@ -136,8 +132,8 @@ pub fn realize( // Find an applicable show rule recipe. for recipe in styles.recipes() { - let guard = Guard::Nth(n); - if recipe.applicable(target) && !target.is_guarded(guard) { + let guard = Guard(n); + if !target.is_guarded(guard) && recipe.applicable(target) { if let Some(content) = try_apply(engine, target, recipe, guard)? { return Ok(Some(content)); } @@ -146,11 +142,8 @@ pub fn realize( } // Apply the built-in show rule if there was no matching recipe. - let guard = Guard::Base(target.func()); - if !target.is_guarded(guard) { - if let Some(showable) = target.with::() { - return Ok(Some(showable.show(engine, styles)?)); - } + if let Some(showable) = target.with::() { + return Ok(Some(showable.show(engine, styles)?)); } Ok(None)