diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-24 14:39:53 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-24 14:53:43 +0200 |
| commit | 50e4002a2a65c27f46895103c59cb775ca60d16d (patch) | |
| tree | dbd43c16ae8456536c89d64d2cfff293bb6b1148 /src/eval/show.rs | |
| parent | 04fb8b288aa7c80607da79db7d085a4820b95a9d (diff) | |
Split `show` into `realize` and `finalize`
Diffstat (limited to 'src/eval/show.rs')
| -rw-r--r-- | src/eval/show.rs | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/eval/show.rs b/src/eval/show.rs index f8d98d52..c374c2df 100644 --- a/src/eval/show.rs +++ b/src/eval/show.rs @@ -13,14 +13,26 @@ pub trait Show: 'static { /// Encode this node into a dictionary. fn encode(&self) -> Dict; - /// Show this node in the given styles and optionally given the realization - /// of a show rule. - fn show( + /// The base recipe for this node that is executed if there is no + /// user-defined show rule. + fn realize(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content>; + + /// Finalize this node given the realization of a base or user recipe. Use + /// this for effects that should work even in the face of a user-defined + /// show rule, for example: + /// - Application of general settable properties + /// - Attaching things like semantics to a heading + /// + /// Defaults to just the realized content. + #[allow(unused_variables)] + fn finalize( &self, ctx: &mut Context, styles: StyleChain, - realized: Option<Content>, - ) -> TypResult<Content>; + realized: Content, + ) -> TypResult<Content> { + Ok(realized) + } /// Convert to a packed show node. fn pack(self) -> ShowNode @@ -55,13 +67,17 @@ impl Show for ShowNode { self.0.encode() } - fn show( + fn realize(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> { + self.0.realize(ctx, styles) + } + + fn finalize( &self, ctx: &mut Context, styles: StyleChain, - realized: Option<Content>, + realized: Content, ) -> TypResult<Content> { - self.0.show(ctx, styles, realized) + self.0.finalize(ctx, styles, realized) } fn pack(self) -> ShowNode { |
