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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
//! The `annotations` feature: a reviewer's marks in a document, passages
//! highlighted and remarks written into the text, under commands that a host
//! configures, one per reviewer.
//!
//! # What an author writes
//!
//! An **annotator** is one reviewer, configured with a command name and
//! optional initials ([`Annotator`], [`AnnotationsConfig`]). The annotators
//! are numbered from zero in configuration order, and an output can give
//! each number its own color. The default configuration declares no
//! annotator, and the feature then declares no command: `\phf` is an unknown
//! command until a host configures an annotator whose command is `phf`.
//!
//! Each annotator's command writes two kinds of annotation:
//!
//! - a **highlight**, a passage the annotator marks, which stays part of the
//! text: written `\phf{…}`, or `\phf … \endphf`;
//! - a **comment**, a remark the annotator writes into the text, which is not
//! part of it: written `\phf[…]`. (A comment in this sense is a reviewer's
//! remark, not a source comment written with `%`.)
//!
//! ```text
//! The result \phf{holds in every case}, as \phf[cite the lemma here] shown.
//! \phf The second form needs no braces, which helps
//! with a long passage.\endphf
//! ```
//!
//! The command takes **one argument**, read by the feature's own parser
//! ([`AnnotationParser`]), which chooses the form by what follows the command
//! (past any whitespace and source comments): a `{` begins a braced group, a
//! `[` a bracketed group, and anything else begins a passage that ends at
//! `\endphf` (`end` followed by the command's name). The argument holds
//! inline content or paragraphs, as written. `\phf{x}[y]` is a highlight of
//! `x` followed by the text `[y]`.
//! The function [`form_of`] reads which form an annotation was written in.
//! The guide for authors describes annotations under
//! [Annotations](crate::guide::language_syntax#annotations).
//!
//! An annotation never becomes a block that holds paragraphs. A blank line
//! inside it is a paragraph break of the text around it, and the annotation
//! continues in the next paragraph; a list inside it is a block of the text
//! around it, still part of the annotation (a cut part around that block, see
//! below), and a displayed formula inside it stays in the inline content the
//! annotation spans. The annotator's initials are shown at the start of the
//! annotation only.
//!
//! # What the feature provides to the pipeline
//!
//! **The element.** Every annotator's command is one element value of the
//! element type [`ANNOTATION`] (`flm.annotations.annotation`), carrying an
//! [`AnnotationElement`]: a macro with one argument, [`TEXT_ARG`], declared in
//! text mode.
//!
//! **Cut parts.** The element is *block-transparent*: its content is laid
//! out as if it were written directly in the content around it
//! ([block-transparent elements](crate::guide::concepts_overview#block-transparent-elements)).
//! Before any paragraph is built, the block-structure pass
//! ([`blocks`](crate::lang::rewrites::blocks)) cuts an
//! annotation whose argument crosses a paragraph break or holds a block into
//! **cut parts**: one node of the annotation's element around each stretch of
//! inline content between paragraph breaks and blocks, and one around each
//! block. Each cut part carries an [`AnnotationPiece`] record, its
//! continuation record, which says which cut part of how many it is. The
//! lowering rules read it to show the initials on the first cut part only,
//! and the `text` backend's rule reads it to open a comment's bracket on the
//! first cut part and close it on the last.
//!
//! **Lowering rules.** A lowering rule ([`LoweringRule`]) says how an element
//! becomes output on a backend. The feature registers these rules. A rule
//! marked as the default for one backend ranks above a rule marked as the
//! default everywhere ([`DefaultMark`]):
//!
//! - [`RULE`] ([`AnnotationRule`]), the default on every backend that has no
//! rule of its own for an annotation: an
//! annotation, or a cut part of one, lowers to a `flm.pres.span` of the
//! role [`HIGHLIGHT_ROLE`] or [`COMMENT_ROLE`] (a `flm.pres.block` of that
//! role for a cut part around a block placed among blocks), with the kind
//! tokens `<command>` and `annotator-<n>` ([`annotator_kind`]). A role is a
//! feature-owned dotted name on a presentation payload that says what a
//! container is, and kind tokens classify it further
//! ([`payload`](crate::stdlib::backends::pres::payload)). A cut part also
//! carries the kind token [`MARK_CONTINUES_KIND`] when a cut part follows
//! it and [`MARK_CONTINUED_KIND`] when one precedes it. The annotator's
//! initials are a margin decoration at the start of the annotation, holding
//! a span of the role [`INITIALS_ROLE`]; a decoration is a node that the
//! lowering driver moves out of the content into an attached slot of the
//! enclosing presentation node
//! ([`Decoration`](crate::stdlib::backends::pres::Decoration)).
//! - [`TEXT_RULE`] ([`AnnotationTextRule`]), the default on the `text`
//! backend: it lowers an annotation as the general rule does, except that a
//! comment is written with its brackets and initials as text and no
//! decoration: `[PhF: remark]` for an annotator with the initials `PhF`.
//! The text backend prints a highlight as `[PhF] passage`.
//! - On the `html` backend, the feature's stylesheet `flm.annotations.style`
//! ([`html`]), which colors each annotation by its annotator's number; the
//! general rule and the `text` backend's rule require it wherever they
//! write an annotation.
//! - On the `latex-rendered` backend, the definition piece
//! `flm.latex.def.flmx.annotations` ([`latex_rendered`]), which the same
//! requirement brings into the style file.
//! - [`latex::LATEX_RULE`] ([`latex::AnnotationLatexRule`]), the default on
//! the `latex-recomposed` backend: it writes the command back as the author
//! wrote it, over the LaTeX package `phfcc`, which makes each annotator's
//! command ([`latex`]).
//!
//! **Settings.** The feature's configuration, [`AnnotationsConfig`], is the
//! value the feature is constructed from; it is fixed when the registry is
//! built
//! ([configuration](crate::guide::concepts_overview#settings-options-and-configuration)),
//! because the commands are part of the language. Written as data, its
//! settings key `annotators` maps each command name to the annotator's other
//! fields, and a host that combines several sources of settings combines
//! that map one annotator at a time. The feature feeds the configuration
//! into the [registry digest](crate::model::digest), the number that changes
//! whenever something about the registry that can change what processing
//! produces changes ([`FeatureBuilder::digest_input`]);
//! [`AnnotationsConfig::digest_bytes`] gives the bytes. The feature also
//! declares one option type, [`AnnotationsRenderOptions`], set per render
//! request: when its field [`hidden`](AnnotationsRenderOptions::hidden) is
//! true, every rule leaves every
//! annotation out of the output, for a clean copy: a highlight is shown as
//! its passage alone and a comment as nothing (the recomposed LaTeX keeps the
//! paragraph breaks a comment held).
//!
//! # Errors
//!
//! A passage opened by `\phf` and not closed by `\endphf` is reported as
//! [`Unterminated`] (`flm.annotations.unterminated`) while the document is
//! parsed. An unknown command (a stray `\endphf`, or `\phf` with no
//! annotator configured) and an unclosed group are reported by the language
//! itself.
//!
//! # Interactions with other features
//!
//! - **Block structure.** The element carries the block-transparent aspect
//! ([`BlockTransparent`]) and a block role per occurrence
//! ([`BlockRoleAspect`]); the block-structure pass
//! ([`blocks`](crate::lang::rewrites::blocks)) cuts it into cut parts.
//! - **Text of a title.** The element carries the aspect [`ApartFromText`]:
//! a comment's remark is not part of the text around it, so that reading
//! the plain text of a run (for example to give an unlabeled heading an
//! identifier from its title) leaves the remark out. A highlight's passage
//! is part of the text.
//! - **Decorations.** The initials are a margin decoration
//! (`flm.pres.deco.margin`); each backend writes it as it writes every
//! margin decoration.
//! - **The `latex-recomposed` backend** lowers the tree before the
//! block-structure pass, so an annotation reaches its rule uncut and is
//! written back as one invocation ([`latex`]).
//! - **The standard features.** The [standard features](crate::stdlib)
//! include the feature under the configuration
//! [`StdlibConfig::annotations`](crate::stdlib::StdlibConfig::annotations).
//!
//! # Items
//!
//! - [`AnnotationsFeature`] and [`feature`] — the feature, under a
//! configuration or the default one.
//! - [`AnnotationsConfig`], [`Annotator`] — the configuration;
//! [`AnnotationsRenderOptions`] — the render option.
//! - [`AnnotationElement`] — the data of each element value of
//! [`ANNOTATION`].
//! - [`AnnotationParser`], [`Form`], [`form_of`] — the argument's parser and
//! the reading of an annotation's form.
//! - [`AnnotationPiece`], [`payload_readers`] — the continuation record of a
//! cut part, and its reader for serialized trees.
//! - [`AnnotationRule`], [`AnnotationTextRule`] — the general rule and the
//! `text` backend's rule; [`html`] and [`latex`] — the rules of the `html`
//! and `latex-recomposed` backends.
//! - [`Unterminated`] — the one condition the feature reports.
//! - The names: [`FEATURE`], [`ANNOTATION`], [`TEXT_ARG`], [`RULE`],
//! [`TEXT_RULE`], the roles [`HIGHLIGHT_ROLE`], [`COMMENT_ROLE`],
//! [`INITIALS_ROLE`], and the kind tokens [`annotator_kind`],
//! [`MARK_CONTINUES_KIND`], [`MARK_CONTINUED_KIND`].
use Arc;
use NodeRef;
use crateSettingsDecl;
use crate;
use crate;
use crateFlm;
use crate;
use crateBlockTransparent;
use crate;
use crateElementSpec;
use crate;
use crateBind;
use cratetext;
pub use ;
pub use ;
pub use Unterminated;
pub use ;
pub use ;
/// The feature's registered name, `annotations`.
pub const FEATURE: &str = "annotations";
/// The declaration of the feature's settings ([`crate::core::settings`]): the
/// fields of [`AnnotationsConfig`] and of [`AnnotationsRenderOptions`] are its
/// settings keys, and the key `annotators` is combined one annotator at a
/// time.
/// The element type of an annotation, `flm.annotations.annotation`: one
/// element value per configured annotator, each carrying an
/// [`AnnotationElement`].
pub const ANNOTATION: &str = "flm.annotations.annotation";
/// The name of an annotation's one argument, `text`: the highlighted passage
/// or the written remark, read by the [`AnnotationParser`].
pub const TEXT_ARG: &str = "text";
/// The role of the span or block a highlight is staged as,
/// `flm.annotations.highlight`.
pub const HIGHLIGHT_ROLE: &str = "flm.annotations.highlight";
/// The role of the span or block a comment is staged as,
/// `flm.annotations.comment`.
pub const COMMENT_ROLE: &str = "flm.annotations.comment";
/// The role of the span that holds an annotator's initials inside the margin
/// decoration at the start of a highlight or a comment,
/// `flm.annotations.initials`.
pub const INITIALS_ROLE: &str = "flm.annotations.initials";
/// The name of the general lowering rule of the element [`ANNOTATION`],
/// `flm.annotations.annotation.lower.default` ([`AnnotationRule`]), the
/// default on every backend.
pub const RULE: &str = "flm.annotations.annotation.lower.default";
/// The name of the lowering rule of the element [`ANNOTATION`] on the `text`
/// backend, `flm.annotations.annotation.lower.text` ([`AnnotationTextRule`]),
/// which writes a comment's brackets and initials as text.
pub const TEXT_RULE: &str = "flm.annotations.annotation.lower.text";
/// Returns the kind token of the annotator numbered `number`,
/// `annotator-<n>`: the second kind token of every annotation's span or block
/// and of its initials' span, after the command's name. A stylesheet selects
/// an annotator's color by this token.
/// The kind token `mark-continues`, carried by every cut part of a cut
/// annotation except the last: the annotation continues in a later cut part.
/// With [`MARK_CONTINUED_KIND`], it lets a stylesheet draw what opens an
/// annotation on its first cut part only and what closes it on its last cut
/// part only. An annotation that was not cut carries neither token.
///
/// A kind token has a meaning only together with the role's class, so the
/// same token on another feature's element is a different token. The kind
/// tokens of a cut part also hold the annotator's command name, which is made
/// of letters only; because of the hyphen, no command name can equal either
/// token.
pub const MARK_CONTINUES_KIND: &str = "mark-continues";
/// The kind token `mark-continued`, carried by every cut part of a cut
/// annotation except the first: the annotation began in an earlier cut part.
/// See [`MARK_CONTINUES_KIND`].
pub const MARK_CONTINUED_KIND: &str = "mark-continued";
/// The data that each element value of [`ANNOTATION`] carries: the annotator
/// whose command writes the annotation, and the annotator's number, its
/// position in the configuration counted from zero.
///
/// The element value also carries three aspects, each implemented on this
/// type: the block role ([`BlockRoleAspect`]) and the cut into cut parts
/// ([`BlockTransparent`]), described at [`AnnotationPiece`], and the content
/// apart from the text ([`ApartFromText`]).
/// A comment is not part of the text around it: its remark, the argument
/// [`TEXT_ARG`], is the annotator's. The plain text of a heading's title that
/// holds a comment therefore leaves the remark out, and so does the
/// identifier made from that text. A highlight's passage is part of the
/// text, so a highlight returns no content reference.
/// Returns the element value of the annotator numbered `number`.
/// Returns the declaration of the command of the annotator numbered `number`:
/// a macro of one argument, [`TEXT_ARG`], read by the feature's
/// [`AnnotationParser`] and laid out as inline content or as paragraphs and
/// blocks, according to its content; declared in text mode.
/// The `annotations` feature ([`FlmFeature`]), constructed from an
/// [`AnnotationsConfig`]: it declares one command per annotator and the
/// lowering rules of an annotation. See the [module documentation](self).
/// Returns the [`AnnotationsFeature`] under the default configuration (no
/// annotator, so no command), ready to be listed in a package entry.
///
/// To list the feature under an [`AnnotationsConfig`] of your own, use
/// `Arc::new(AnnotationsFeature::new(config))`, or pass the configuration to
/// the standard features with
/// [`StdlibConfig::annotations`](crate::stdlib::StdlibConfig::annotations).