1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
//! The `toc` feature: the document's table of contents, as a table of entries
//! a program can read and as a piece a backend places before the content.
//!
//! # What it lists
//!
//! A *heading* is any node whose element carries the sectioning aspect
//! ([`Sectioning`](crate::model::aspects::Sectioning)): the standard headings
//! (`\section` to `\subparagraph`) and any heading kind an extension declares
//! alike. The feature lists, in the run's document order, every heading that
//! the aspect says is listed ([`in_toc`](crate::model::aspects::Sectioning::in_toc):
//! not of a kind declared `skip_toc`, not written `toc=false`) and whose level
//! ([`level`](crate::model::aspects::Sectioning::level)) is at most the
//! setting [`depth`](TocOptions::depth) (3 by default: sections, subsections
//! and subsubsections). A starred heading is listed like any other. A heading
//! inside a file brought in as a heading input comes where that file is placed.
//!
//! Each entry shows what the aspect returns for the heading
//! ([`toc_title`](crate::model::aspects::Sectioning::toc_title)): for a
//! standard heading, the alternative title written with the heading key
//! `alt=`, and the heading's title otherwise. A footnote inside the title
//! shows its mark in the entry, and its note is listed once, where the heading
//! stands.
//!
//! # The table and the piece
//!
//! The stage [`BUILD`] (`flm.toc.build`, [`BuildToc`]) writes two tables:
//!
//! - [`ENTRIES`] (`flm.toc.entries`, [`TocEntries`]): one [`TocEntry`] per
//! listed heading, in document order: the heading's address, its level, its
//! first reference point and the content its entry shows. The table holds no
//! number and no anchor: a reader takes both from the counters and anchors
//! tables at the point of use, as the heading's own lowering rule does, so
//! that every output and the table agree. A program demands the table by its
//! name and reads it without rendering anything.
//! - [`PIECE`] (`flm.toc`, a [`Piece`]): the table of contents as content, one
//! synthesized value of nested lists. A *piece* is a document-level
//! synthesized value that a backend places beside the document's content
//! (see [pieces](crate::guide::concepts_overview#pieces)).
//!
//! The piece is declared before the content and **off by default**
//! ([`PieceDecl::default_on`]): a render places it only when its pieces
//! option includes it (`pieces.include: [flm.toc]`), or when the compose
//! template of the output requires it. Among the pieces placed before the
//! content, it comes after the metadata's.
//!
//! # The shape of the piece
//!
//! The value holds three synthesized elements, which no document can write:
//! [`PIECE`] (`flm.toc`), the root, holding one [`LIST`] (`flm.toc.list`);
//! a list holds [`ENTRY`] (`flm.toc.entry`) nodes, each carrying a
//! [`TocEntryPayload`] and holding the entry's title, then, where the entry
//! has sub-entries, one list of them. The entries are nested by relative
//! level: an entry whose level is greater than the level of the entry before
//! it at the same depth goes into a new list inside that entry; a level gap (a
//! subsubsection directly under a section) nests one list deeper, not two;
//! the first entry, at any level, is a top-level entry. A heading left out
//! (too deep, or not listed) is skipped: its listed sub-headings are nested
//! among the headings kept.
//!
//! The lowering rules ([`rules`]) stage, on every backend:
//!
//! ```text
//! flm.pres.block { role: flm.toc, kinds: [toc], doc_role: Toc }
//! └ flm.pres.list { kinds: [unnumbered, toc], entry_levels: [<each entry's level>] }
//! per entry: label ⇒ nothing
//! item ⇒ flm.pres.link { href: "#<anchor>", kind: toc }
//! ├ flm.pres.span { role: flm.toc.entry.number } the number
//! ├ " "
//! └ the title
//! the sub-list, where there is one
//! ```
//!
//! Each entry's level is its heading's level, from its [`TocEntryPayload`].
//! The number is the heading's number alone, without the word and the
//! delimiters a reference writes. An entry without a number has no number
//! span and no space; an entry whose heading has no anchor has no link.
//!
//! On the HTML page ([`html`]), the block is a `<nav>` with the role
//! `doc-toc`, and the page carries the feature's stylesheet [`STYLE`]
//! (`flm.toc.style`). The plain-text backend prints the nested lists as it
//! prints every list whose labels are all empty: one entry per paragraph, at
//! the left margin, so the nesting shows only through the numbers. In the
//! rendered LaTeX the block is written through the backend's contract and the
//! requirement brings in the feature's definition piece
//! ([`latex_rendered`]): the title, the entries linked to the headings, and
//! each entry's page number as LaTeX gives it. In the
//! recomposed LaTeX the three elements write nothing ([`latex`]): LaTeX builds
//! its own table of contents, and the piece is not placed on that output
//! unless a render names it for that backend.
//!
//! # Settings
//!
//! The option type [`TocOptions`] (`depth`), bound on the document or on the
//! render request ([`Bind::Either`]): `flm: {features: {toc: {depth: 2}}}` in
//! a front matter, `-O toc.depth=2` on the command line.
//!
//! # Interactions with other features
//!
//! - `index` and `refpoints`: the stage reads the element index, and the table
//! of reference points where the `refpoints` feature is registered; without
//! it, no entry has a point, and so no number and no link.
//! - `numbering` and `refs`: the rules read the counters and anchors tables
//! where they are computed, under peer declarations
//! ([`PeerName`](crate::core::registry::PeerName)), so the feature builds in
//! a registry without either.
//! - `pieces`: the piece declaration is a peer contribution to the slot
//! [`pieces::SLOT`]; without the `pieces` feature no backend places it.
//!
//! # Items
//!
//! - The feature: [`Toc`], [`feature`], [`FEATURE`], [`TocOptions`].
//! - The table: [`ENTRIES`], [`TocEntries`], [`TocEntry`].
//! - The stage: [`BUILD`], [`BuildToc`], [`TocFailed`].
//! - The piece and its elements: [`PIECE`], [`LIST`], [`ENTRY`],
//! [`TocEntryPayload`], [`KIND_TOC`], [`NUMBER_ROLE`].
//! - The rules: [`rules`], [`latex`]. The style identifier, the stylesheet
//! and the rendered LaTeX's definition piece: [`STYLE`], [`html`],
//! [`latex_rendered`].
use Arc;
use NodeRef;
use SerialValue;
use crate;
use crate;
use crate;
use crateSettingsDecl;
use crate;
use crateNodeAddr;
use crate;
use crateBind;
use cratepieces;
use crate;
pub use ;
/// The feature's registered name, `toc`; also its settings key.
pub const FEATURE: &str = "toc";
/// The typed name of the table of entries, `flm.toc.entries` ([`TocEntries`]);
/// like every table name, it is also the capability a caller demands to have
/// it computed.
pub const ENTRIES: = new;
/// The name of the piece `flm.toc`: the name of its table (of type
/// [`Piece`]), of its declaration, and of the synthesized element at the root
/// of its content.
pub const PIECE: &str = "flm.toc";
/// The name of the synthesized element of a list of entries, `flm.toc.list`.
pub const LIST: &str = "flm.toc.list";
/// The name of the synthesized element of one entry, `flm.toc.entry`, which
/// carries a [`TocEntryPayload`].
pub const ENTRY: &str = "flm.toc.entry";
/// The name of the stage that writes the table of entries and the piece,
/// `flm.toc.build` ([`BuildToc`]).
pub const BUILD: &str = "flm.toc.build";
/// The feature's style identifier, `flm.toc.style`, which the general rule
/// of the root ([`RootRule`](rules::RootRule)) requires: the stylesheet on the
/// HTML page ([`html::stylesheet`]).
pub const STYLE: &str = "flm.toc.style";
/// The kind token of the block and of the lists the rules stage, `toc`: a
/// stylesheet or a program's lowering rule can select on it.
pub const KIND_TOC: &str = "toc";
/// The role of the span holding an entry's number, `flm.toc.entry.number`.
pub const NUMBER_ROLE: &str = "flm.toc.entry.number";
/// The default of [`TocOptions::depth`], 3.
pub const DEFAULT_DEPTH: u32 = 3;
/// The options of the `toc` feature, bound on the document or on the render
/// request ([`Bind::Either`]); in data, the settings of the feature `toc`.
///
/// # Examples
///
/// ```
/// use flm_core::stdlib::features::toc::TocOptions;
///
/// assert_eq!(TocOptions::default().depth, 3);
/// ```
/// One entry of the table of contents: a listed heading.
/// The table of entries, `flm.toc.entries` ([`ENTRIES`]): one [`TocEntry`] per
/// listed heading, in the run's document order. See the [module
/// documentation](self).
///
/// The table is a document fact ([`PieceClass::DocumentFact`]) when it holds
/// an entry: it describes the document's own headings.
/// The payload of an [`ENTRY`] node: the heading's first reference point,
/// where it has one, and its level. The entry's rule reads the number and the
/// anchor of the point from the counters and anchors tables.
/// The declaration of the feature's settings: the field of [`TocOptions`]
/// (`depth`) is its settings key.
/// The `toc` feature: the option type [`TocOptions`], the table [`ENTRIES`],
/// the stage [`BUILD`], the piece [`PIECE`] with its elements, lowering rules
/// and stylesheet (see the [module documentation](self)).
///
/// Use [`feature()`] to obtain it as a value a package entry can list.
;
/// Returns the [`Toc`] feature, ready to be listed in a package entry.
///
/// # Examples
///
/// ```
/// use flm_core::stdlib::features::toc;
///
/// assert_eq!(toc::feature().info().name.as_str(), toc::FEATURE);
/// ```