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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
//! The `metadata` feature: the document's metadata (its title, its authors, its date, and
//! any other key the author writes about the document) and the three pieces that show
//! the title, the authors and the date before the document's content.
//!
//! # What an author writes, and what it produces
//!
//! The title, the date and each author's name, affiliations and notes are FLM text,
//! not plain text: a title may be `The \emph{Art} of \(x^2\)`. An author may have,
//! beside a name, affiliations, an email address (a plain text) and notes
//! ([`MetaAuthor`]). The author of the document does not write them with commands in
//! the document's text; the program that processes the document sets them. The `flm`
//! program reads them from the root keys `title`, `author` and `date` of a file's
//! front matter (the block of YAML at the top of the file). Each FLM text is parsed as
//! inline content when the document is processed, and a problem in it is reported at
//! its place in the file that holds it.
//!
//! A *piece* is a document-level synthesized value that a backend places before or
//! after the document's content ([`Piece`]; see
//! [pieces](crate::guide::concepts_overview#pieces)). The feature builds three pieces,
//! each placed before the content, and placed by every render unless the render
//! options leave it out
//! ([`PieceDecl::default_on`](crate::core::piece::PieceDecl::default_on)): [`TITLE`]
//! (`flm.metadata.title`), [`AUTHOR`] (`flm.metadata.author`) and [`DATE`]
//! (`flm.metadata.date`). On each output:
//!
//! - on the plain-text, HTML and rendered-LaTeX outputs, each piece is a block of its
//! own whose role is its element's name and whose kind token is `metadata`
//! ([`KIND_METADATA`]; a `<div>` on HTML). The title and the date hold one
//! paragraph. The authors hold each author, one after the other, as a group of
//! lines: the name, each affiliation, the email address (a link to `mailto:` and
//! the address) and each note, each on a line of its own in a span whose role is
//! the part's element name ([`rules`]). The HTML page also uses the words of the
//! title piece as its `<title>`;
//! - on the recomposed LaTeX, each piece is what a LaTeX document passes to `\title`,
//! `\author` and `\date`: the title and the date are their content written back as
//! LaTeX; each author is the name, `\thanks{…}` for each note, then each affiliation
//! and the email address after `\\`, the authors joined by `\and` ([`latex`]). That
//! backend places a piece only where the render options of the `pieces` feature
//! list it ([pieces in the recomposed
//! LaTeX](crate::guide::rendering#pieces-in-the-recomposed-latex)).
//!
//! A document without metadata places nothing: each piece holds no content. The other
//! keys of the metadata ([`DocMeta::other`]) and of an author ([`MetaAuthor::other`]) are
//! data the library does not show; the program may pass them to the tool it builds the
//! final output with, such as a template.
//!
//! # What a program provides
//!
//! The metadata is an option value of the option type [`DocMeta`], bound per document:
//! an option type is a plain Rust struct a feature declares once, whose values are set
//! on a document or on a render request ([`crate::model::options`]). A program sets it
//! on the document it builds
//! ([`Doc::with_options`](crate::model::doc::Doc::with_options)). A program that holds
//! the metadata as data (for example the root keys of a front matter) reads it with
//! [`DocMeta::from_data`], whose form ([`data`]) is the same for every program: `title`
//! and `date` one text each, `author` one author or a list of authors, an author being
//! a text (the name) or a map (`name`, `affiliation`, `email`, `note`). Each text is
//! kept as the author wrote it, with the place it was written at ([`MetaText`],
//! [`MetaPlace`]). See
//! [the document's metadata](crate::guide::embedding#the-documents-metadata) in the
//! embedding guide.
//!
//! # What the feature registers
//!
//! - the option type [`DocMeta`], bound per document;
//! - the stage [`BUILD`] (`flm.metadata.build`, [`BuildMetadata`]), which parses the
//! title, the authors and the date, numbers the distinct affiliations of the document
//! ([`AffiliationPayload`]), and writes the tables of the three pieces. It provides
//! the capability [`READ`] (`flm.metadata.read`), a member of the collection
//! [`flm.validated`](crate::stdlib::VALIDATED) that every standard workflow
//! demands, so that checking a document reports the problems the parse of its
//! metadata finds. A problem found only when a piece is lowered for an output, such
//! as a footnote in the title, is reported by a render only;
//! - the three pieces [`TITLE`], [`AUTHOR`] and [`DATE`], each a table and a piece
//! declaration contributed to the service slot of the `pieces` feature
//! ([`pieces::SLOT`]);
//! - the synthesized elements of the three pieces, of one author ([`AUTHOR_ENTRY`],
//! `flm.metadata.author.entry`) and of its parts ([`AUTHOR_NAME`],
//! [`AUTHOR_AFFILIATION`], [`AUTHOR_EMAIL`], [`AUTHOR_NOTE`]); no document can write
//! them. Their default lowering rules are in [`rules`], and their rules on the
//! recomposed LaTeX in [`latex`];
//! - the diagnostic `flm.metadata.failed` ([`MetadataFailed`]), for a part of the
//! metadata that could not be built.
//!
//! # Interactions with other features
//!
//! - `pieces` ([`pieces`]): the feature contributes its three piece declarations to
//! that feature's service slot as peer contributions (values for a service slot
//! another feature declares; see [services and service
//! slots](crate::guide::concepts_overview#services-and-service-slots)); without the
//! `pieces` feature no backend places the metadata.
//! - The LaTeX family ([`latex`](crate::stdlib::backends::latex)): the rules on the
//! recomposed LaTeX are registered with peer declarations of the backend and of the
//! macro construct, so that a registry without the LaTeX features still builds, with
//! those rules set aside (excluded from rule selection; see
//! [`PeerName`](crate::core::registry::PeerName)).
//! - `check` ([`CheckWorkflow`](crate::stdlib::CheckWorkflow)): the capability
//! [`READ`] joins the collection `flm.validated`.
//!
//! # Items
//!
//! - The feature: [`Metadata`], [`feature`], [`FEATURE`].
//! - The metadata: [`DocMeta`], [`MetaAuthor`], [`MetaText`], [`MetaPlace`]; written as
//! data: [`data`], [`DocMeta::from_data`], [`metadata_schema`], [`TITLE_KEY`],
//! [`AUTHOR_KEY`], [`DATE_KEY`], [`NAME_KEY`], [`AFFILIATION_KEY`], [`EMAIL_KEY`],
//! [`NOTE_KEY`], [`MetaPath`], [`MetaStep`], [`MetaDataError`].
//! - The pieces and their elements: [`TITLE`], [`AUTHOR`], [`AUTHOR_ENTRY`],
//! [`AUTHOR_NAME`], [`AUTHOR_AFFILIATION`], [`AUTHOR_EMAIL`], [`AUTHOR_NOTE`], [`DATE`],
//! [`KIND_METADATA`]; the payloads [`AffiliationPayload`] and [`EmailPayload`].
//! - The stage: [`BUILD`], [`READ`], [`BuildMetadata`], [`MetadataFailed`].
//! - The lowering rules: [`rules`] ([`MetaTextRule`], [`AuthorRule`], [`EntryRule`],
//! [`PartRule`], [`EmailRule`]) and [`latex`].
//! - The style identifier [`STYLE`] ([`stylesheet`]), which the general rules
//! require at every piece they stage, and the `latex-rendered` definition
//! piece delivering it, [`latex_rendered`].
use BTreeMap;
use ;
use Arc;
use NodeRef;
use SerialValue;
use crate;
use crate;
use crate;
use crateName;
use crateBind;
use cratepieces;
use crateVALIDATED;
pub use ;
pub use ;
pub use ;
/// The feature's registered name, `metadata`.
pub const FEATURE: &str = "metadata";
/// The name of the title piece, `flm.metadata.title`. It is also the name of the
/// piece's table and of the synthesized element at the root of the piece's
/// content.
pub const TITLE: &str = "flm.metadata.title";
/// The name of the authors piece, `flm.metadata.author`. It is also the name of the
/// piece's table and of the synthesized element at the root of the piece's
/// content, which holds one [`AUTHOR_ENTRY`] node per author.
pub const AUTHOR: &str = "flm.metadata.author";
/// The name of the synthesized element of one author in the authors piece,
/// `flm.metadata.author.entry`. It holds the author's parts, in this order: one
/// [`AUTHOR_NAME`] node, one [`AUTHOR_AFFILIATION`] node per affiliation, one
/// [`AUTHOR_EMAIL`] node when the author has an email address, and one
/// [`AUTHOR_NOTE`] node per note.
pub const AUTHOR_ENTRY: &str = "flm.metadata.author.entry";
/// The name of the synthesized element of an author's name,
/// `flm.metadata.author.name`: it holds the name as inline content.
pub const AUTHOR_NAME: &str = "flm.metadata.author.name";
/// The name of the synthesized element of one affiliation of an author,
/// `flm.metadata.author.affiliation`: it holds the affiliation as inline content,
/// and carries the affiliation's number ([`AffiliationPayload`]).
pub const AUTHOR_AFFILIATION: &str = "flm.metadata.author.affiliation";
/// The name of the synthesized element of an author's email address,
/// `flm.metadata.author.email`: it holds no content, and carries the address
/// ([`EmailPayload`]).
pub const AUTHOR_EMAIL: &str = "flm.metadata.author.email";
/// The name of the synthesized element of one note about an author,
/// `flm.metadata.author.note`: it holds the note as inline content.
pub const AUTHOR_NOTE: &str = "flm.metadata.author.note";
/// The name of the date piece, `flm.metadata.date`. It is also the name of the
/// piece's table and of the synthesized element at the root of the piece's
/// content.
pub const DATE: &str = "flm.metadata.date";
/// The name of the stage that parses the metadata and builds the three pieces,
/// `flm.metadata.build` ([`BuildMetadata`]).
pub const BUILD: &str = "flm.metadata.build";
/// The name of the capability `flm.metadata.read`: the document's metadata has
/// been parsed, and every problem the parse found has been reported. It is a member
/// of the collection [`flm.validated`](crate::stdlib::VALIDATED), so every
/// standard workflow runs the stage [`BUILD`].
pub const READ: &str = "flm.metadata.read";
/// The kind token that the blocks staged by the rules of the three pieces carry,
/// `metadata`: a stylesheet or a program's lowering rule can select on it (see
/// [`pres::payload`](crate::stdlib::backends::pres::payload)).
pub const KIND_METADATA: &str = "metadata";
/// The feature's style identifier, `flm.metadata.style`, which the general rules
/// ([`MetaTextRule`], [`AuthorRule`]) require at every piece they stage. On
/// the `html` backend it names the feature's stylesheet ([`stylesheet`]);
/// on the `latex-rendered` backend
/// the feature's definition piece ([`latex_rendered::piece`]) delivers it.
pub const STYLE: &str = "flm.metadata.style";
/// The style definition [`STYLE`] on the `html` backend: one cascade layer that
/// sets the title large and bold, and the authors and the date indented under the
/// title, the authors one below the other, an author's affiliations, email
/// address and notes smaller than the name; the sizes, the indentation and the
/// spaces are custom properties it declares (`--flm-metadata-title-size`,
/// `--flm-metadata-line-indent`, `--flm-metadata-author-detail-size`, …). It
/// selects on the blocks and spans the general rules stage (their role and the
/// kind token [`KIND_METADATA`]), so it applies whatever compose template places
/// the pieces. It sets no rule between the pieces and the content: that belongs to
/// the page that places them.
/// The payload of an [`AUTHOR_AFFILIATION`] node: the affiliation's number.
///
/// The stage [`BUILD`] numbers the distinct affiliations of the document from 1,
/// in the order in which they first appear. Two affiliations whose texts are the
/// same once the whitespace at both ends is trimmed are the same affiliation,
/// and carry the same number. No rule of this feature writes the number: it is
/// there for a lowering rule that marks each author with the numbers of the
/// author's affiliations and lists the affiliations once.
/// The payload of an [`AUTHOR_EMAIL`] node: the address, as the author wrote it.
/// A text of the metadata as the author wrote it, and where it was written. The
/// stage [`BUILD`] parses it as inline FLM content, except an author's email
/// address ([`MetaAuthor::email`]), which is a plain text.
/// Where a text of the metadata begins: the file, the line and the column, the
/// line and the column counted from 1.
/// One author of the document: the name, the affiliations, the email address,
/// the notes, and every other key the author's entry holds. Each text keeps the
/// place it was written at, so that a problem in an affiliation is reported at
/// the affiliation.
///
/// The name, each affiliation and each note are FLM text, which the stage
/// [`BUILD`] parses as inline content. The email address is a plain text: it is
/// not parsed, and nothing checks its form.
///
/// # Examples
///
/// ```
/// use flm_core::stdlib::features::metadata::{MetaAuthor, MetaText};
///
/// let ada = MetaAuthor::new(MetaText::new("Ada Lovelace"))
/// .affiliation(MetaText::new(r"University of \emph{X}"))
/// .email(MetaText::new("ada@example.com"))
/// .note(MetaText::new("Corresponding author"));
/// assert_eq!(ada.affiliations.len(), 1);
/// ```
// A data value has no hash of its own; its written form stands for it, one
// written form per value.
/// Feeds `other`, a map of data values, to `state`: its length, then each key
/// and the written form of its value.
/// The document's metadata: the option type the `metadata` feature declares, bound
/// per document (see the [module documentation](self)). A program sets its value
/// on the document ([`Doc::with_options`](crate::model::doc::Doc::with_options)),
/// or reads it from data with [`DocMeta::from_data`].
///
/// The default holds nothing, and a document whose metadata holds nothing
/// places none of the three pieces.
///
/// # Examples
///
/// ```
/// use flm_core::model::doc::{Doc, DocContent};
/// use flm_core::model::options::OptionValues;
/// use flm_core::stdlib::features::metadata::{DocMeta, MetaAuthor, MetaText};
///
/// let meta = DocMeta::default()
/// .title(MetaText::new(r"On \emph{flexible} markup"))
/// .author(MetaAuthor::new(MetaText::new("Ada")).affiliation(MetaText::new("University of X")))
/// .author(MetaAuthor::new(MetaText::new("Grace")));
/// let doc = Doc::with_options(DocContent::new(), OptionValues::new().with(meta));
/// # let _ = doc;
/// ```
// A data value has no hash of its own; its written form stands for it, one
// written form per value.
/// The `metadata` feature: the option type [`DocMeta`], the stage [`BUILD`], the
/// three pieces and their elements and lowering rules (see the [module
/// documentation](self)).
///
/// Use [`feature()`] to obtain it as a value a package entry can list.
;
/// Returns the [`Metadata`] feature, ready to be listed in a package entry.
///
/// # Examples
///
/// ```
/// use flm_core::stdlib::features::metadata;
///
/// assert_eq!(metadata::feature().info().name.as_str(), metadata::FEATURE);
/// ```