flm_core/stdlib/features/quote/html.rs
1//! The stylesheet of the [`quote`](super) feature on the `html` backend,
2//! `flm.quote.style` ([`stylesheet`]), and the markup it selects on.
3//!
4//! On the `html` backend a quotation is lowered by the general rule
5//! [`QuoteRule`](super::QuoteRule), into the shared presentation vocabulary;
6//! the rule also requires (records a requirement for) the feature's style
7//! identifier [`STYLE`] (`flm.quote.style`), which on the `html` backend
8//! names this stylesheet, a style definition ([`StyleDef`]) that the backend
9//! delivers with the page
10//! ([style and script definitions](crate::guide::concepts_overview#style-and-script-definitions)).
11//! The HTML itself comes from the backend's rules for the presentation
12//! elements, the same for every feature
13//! ([the HTML contract](crate::guide::rendering#the-html-contract)).
14//!
15//! # The markup
16//!
17//! A quotation is a block of role `flm.quote`. The HTML backend's table of
18//! block tags ([`BLOCK_TAGS`](crate::stdlib::backends::html::conventions::BLOCK_TAGS))
19//! writes it as a `<blockquote>` for every quote environment, with the
20//! environment's name as its kind token in `data-flm-kind`. Each quotation
21//! section is a `<div>` whose second class is its role's class:
22//! `flm-quote-text`, `flm-quote-lines`, `flm-quote-attributed` or
23//! `flm-quote-block`:
24//!
25//! ```html
26//! <blockquote class="flm-pres-block flm-quote" data-flm-kind="quote">
27//! <div class="flm-pres-block flm-quote-text">
28//! <p class="flm-pres-par">To be or not to be.</p>
29//! </div>
30//! <div class="flm-pres-block flm-quote-attributed">
31//! <p class="flm-pres-par">Shakespeare</p>
32//! </div>
33//! </blockquote>
34//! ```
35//!
36//! A lines section holds a run of lines. A line with a left indentation
37//! carries it as a custom property in its `style` attribute; a line without
38//! one has no `style` attribute:
39//!
40//! ```html
41//! <blockquote class="flm-pres-block flm-quote" data-flm-kind="address">
42//! <div class="flm-pres-block flm-quote-lines">
43//! <div class="flm-pres-lines">
44//! <div class="flm-pres-line" data-flm-align="left">123 Main St</div>
45//! <div class="flm-pres-line" style="--flm-element-indent-left: calc(1 * var(--flm-tab))" data-flm-align="left">City, ST 12345</div>
46//! </div>
47//! </div>
48//! </blockquote>
49//! ```
50//!
51//! The backend writes no tag or class specific to this feature: the classes
52//! come from the role and the kind tokens, as for every feature, so a
53//! stylesheet selects every quotation by the role's class (`.flm-quote`), a
54//! quotation section by its role's class, and one environment by its kind token
55//! (`.flm-quote[data-flm-kind~="address"]`).
56//!
57//! # The stylesheet
58//!
59//! The stylesheet [`stylesheet`] (`flm.quote.style`) is one cascade layer
60//! that sets a quotation apart from the text around it. Every quotation is
61//! indented on both sides and spaced above and below. A `quote`, and every
62//! environment a host configures, has a faint background and inner space, and
63//! its passages and lines are in italics; a `blockquote` is only indented, and
64//! an `address` is indented with its lines slightly smaller. A block section
65//! has a thin rule on its left, and an attribution is set on a line of its
66//! own, aligned to the right, after a dash. Each rule selects an environment
67//! by its kind token, never by the tag, and selects a quotation section only
68//! as a direct child of its quotation, so that a quotation nested in another
69//! keeps its own look. Every value it uses is a custom property declared in
70//! the stylesheet (`--flm-quote-indent`, `--flm-quote-background`,
71//! `--flm-quote-attributed-lead` and the others), which a page sets to change
72//! the look without writing a rule. A quotation also sets
73//! `--flm-margin-note-inset` to how far it is indented from the right of the
74//! text, so that a note shown in the margin and written inside the quotation
75//! still reaches the page's column of notes (the margin rule of the HTML
76//! backend's core stylesheet
77//! ([`STYLE_CORE`](crate::stdlib::backends::html::conventions::STYLE_CORE))
78//! reads it).
79//!
80//! The general rule requires the stylesheet at every quotation, so that a
81//! page holding no quotation carries none of it.
82
83use crate::core::registry::{BuildError, DefContent, FeatureBuilder, StyleDef};
84use crate::model::names::Name;
85
86/// The identifier of the feature's stylesheet, `flm.quote.style`
87/// ([`stylesheet`]), which the general rule [`QuoteRule`](super::QuoteRule)
88/// requires at every quotation.
89pub const STYLE: &str = "flm.quote.style";
90
91/// Returns the feature's stylesheet, `flm.quote.style`, as a style
92/// definition: one cascade layer that sets a quotation apart from the text
93/// around it, every value a custom property it declares. See the [module
94/// documentation](self#the-stylesheet).
95pub fn stylesheet() -> StyleDef {
96 StyleDef {
97 id: Name::from(STYLE),
98 content: vec![DefContent::Inline(String::from(include_str!("css/quote.css")))],
99 docs: String::from("a quotation set apart from the text around it, and its attribution from its passage"),
100 }
101}
102
103/// Registers what the feature contributes to the `html` backend: the
104/// stylesheet ([`stylesheet`]).
105///
106/// # Errors
107///
108/// Never fails: the declaration it makes ([`FeatureBuilder::style_def`]) is
109/// checked when the registry is built.
110pub(super) fn register(b: &mut FeatureBuilder<'_>) -> Result<(), BuildError> {
111 b.style_def(stylesheet())
112}
113
114#[cfg(test)]
115mod tests {
116 use super::*;
117
118 #[test]
119 fn the_stylesheet_names_itself_and_is_one_layer() {
120 let style = stylesheet();
121 assert_eq!(style.id.as_str(), STYLE);
122 let [DefContent::Inline(css)] = style.content.as_slice() else { panic!("one inline part") };
123 assert_eq!(css.lines().next(), Some("/* flm.quote.style */"));
124 assert_eq!(css.matches("@layer flm {").count(), 1);
125 }
126}