zenith_core/ast/block_style.rs
1//! `block role="…"` style declaration AST type.
2//!
3//! A `block` decl maps a markdown block role (h1–h6, p, blockquote, li,
4//! code-block, hr) to a set of style and spacing properties. It is a
5//! declaration child — NOT a renderable node — and may appear at three scopes:
6//! document body, page, and text node. The cascade precedence is text > page >
7//! document (highest specificity wins). Block decls are data-only in this
8//! unit; the layout engine consumes them in a later unit.
9
10use crate::ast::value::{Dimension, PropertyValue};
11
12/// The recognized block-role vocabulary. Used by `zenith schema block` for
13/// documentation and by the formatter for canonical KDL emission.
14///
15/// Values: h1, h2, h3, h4, h5, h6, p, blockquote, li, code-block, hr.
16pub const BLOCK_ROLE_VOCAB: &[&str] = &[
17 "h1",
18 "h2",
19 "h3",
20 "h4",
21 "h5",
22 "h6",
23 "p",
24 "blockquote",
25 "li",
26 "code-block",
27 "hr",
28];
29
30/// Style + spacing declaration for a single markdown block role.
31///
32/// Declared as a `block role="h1" …` leaf child at document, page, or text
33/// scope. All style fields are optional; absent fields fall through to the
34/// next scope in the cascade (text > page > document) and ultimately to the
35/// node-level default. An empty `block` decl (only `role` set) is valid and
36/// simply acts as a noop override.
37#[derive(Debug, Clone, PartialEq)]
38pub struct BlockStyle {
39 /// The block role this decl targets (e.g. `"h1"`, `"p"`, `"blockquote"`).
40 pub role: String,
41 /// Override font family (token ref or literal).
42 pub font_family: Option<PropertyValue>,
43 /// Override font size (token ref, pixel literal, or dimension ref).
44 pub font_size: Option<PropertyValue>,
45 /// Override font weight (token ref or literal).
46 pub font_weight: Option<PropertyValue>,
47 /// Override text fill color (token ref or literal).
48 pub fill: Option<PropertyValue>,
49 /// Override text alignment: `"left"`, `"center"`, `"right"`, `"justify"`.
50 pub align: Option<String>,
51 /// Override italic rendering.
52 pub italic: Option<bool>,
53 /// Extra space inserted above the block (resolved at compile time).
54 pub space_before: Option<Dimension>,
55 /// Extra space inserted below the block (resolved at compile time).
56 pub space_after: Option<Dimension>,
57}