diplodocus 0.15.0

Build coherent documentation websites for polyglot software projects.
Documentation
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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
//! Portable intermediate representation for extracted documentation.
//!
//! [`Workspace`] is the schema-versioned snapshot envelope. Map keys are the
//! authoritative entity IDs, with targets and items scoped to their package.
//! Maps and sets have deterministic order; vectors retain declaration, syntax,
//! or output-event order. [`SourcedDocument`] adds source context to the existing
//! [`Document`] tree, and signatures retain evidence independent of item prose.
//!
//! Paths name declared repositories and normalized relative locations, never
//! local checkout roots. Identity helpers assign canonical keys without extraction.
//! This model does not resolve source declarations, gather evidence,
//! or execute cells. Decoding output representations also grants no rendering
//! trust; serialized HTML remains an [`UnvalidatedHtml`] candidate.

use serde::{Deserialize, Serialize};

mod cpp;
mod identity;
mod languages;
mod outputs;
mod package_metadata;
mod provenance;
mod signatures;
mod workspace;

pub use cpp::*;
pub use identity::*;
pub use languages::*;
pub use outputs::*;
pub use package_metadata::*;
pub use provenance::*;
pub use signatures::*;
pub use workspace::*;

/// A zero-based, half-open byte range in one source file.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct SourceSpan {
    /// First byte included in the range.
    pub start: usize,
    /// First byte after the range.
    pub end: usize,
}

/// A string value and the source bytes that declared it.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SpannedString {
    /// Cooked semantic value.
    pub value: String,
    /// Source range of the value.
    pub span: SourceSpan,
}

/// Source-ordered attributes attached to a document construct.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Attributes {
    /// Optional identifier.
    pub identifier: Option<SpannedString>,
    /// Classes in source order.
    pub classes: Vec<SpannedString>,
    /// Key-value attributes in source order.
    pub key_values: Vec<AttributeKeyValue>,
}

/// One key-value attribute.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AttributeKeyValue {
    /// Attribute key.
    pub key: SpannedString,
    /// Attribute value.
    pub value: SpannedString,
}

/// Generic YAML value retained from document metadata or cell options.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum MetadataValue {
    /// An absent YAML value.
    Null {
        /// Source range of the empty value slot.
        span: SourceSpan,
    },
    /// A cooked scalar together with its raw spelling.
    Scalar {
        /// Raw scalar source.
        raw: String,
        /// Cooked scalar value.
        value: String,
        /// Source range of the scalar.
        span: SourceSpan,
    },
    /// A source-ordered mapping.
    Mapping {
        /// Mapping entries in source order, including duplicate keys.
        entries: Vec<MetadataEntry>,
        /// Source range of the mapping.
        span: SourceSpan,
    },
    /// A source-ordered sequence.
    Sequence {
        /// Sequence values in source order.
        items: Vec<MetadataValue>,
        /// Source range of the sequence.
        span: SourceSpan,
    },
    /// YAML syntax the portable model cannot interpret safely.
    Unsupported {
        /// Original source bytes.
        raw: String,
        /// Source range of the value.
        span: SourceSpan,
    },
}

/// One source-ordered metadata mapping entry.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MetadataEntry {
    /// Cooked key and its range.
    pub key: SpannedString,
    /// Entry value.
    pub value: MetadataValue,
    /// Full declaration range.
    pub span: SourceSpan,
}

/// A parsed authored document.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Document {
    /// Full document range.
    pub span: SourceSpan,
    /// Optional authored-page YAML front matter.
    pub frontmatter: Option<MetadataValue>,
    /// Renderable blocks in source order.
    pub blocks: Vec<Block>,
}

/// A block in an authored document.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum Block {
    /// API documentation embedded by a static authored assembly directive.
    ApiDocumentation {
        /// Canonical item whose signatures and documentation are presented.
        item: ItemReference,
        /// Exact item and member documents selected by the authored directive.
        selection: Vec<ItemReference>,
        /// Page-local anchor used by the generated index.
        identifier: String,
        /// Authored directive range, independent of the item's source ranges.
        span: SourceSpan,
    },
    /// An explicitly declared browser component with ordinary Markdown fallback.
    Component {
        /// Component name, optional instance props, and optional local anchor.
        attributes: Attributes,
        /// Content retained when scripting is unavailable.
        blocks: Vec<Block>,
        /// Range in the enclosing document.
        span: SourceSpan,
    },
    /// Heading-delimited panels presented as an interactive tabset in HTML.
    Tabset {
        /// Tabset identifier, classes, and optional synchronization group.
        attributes: Attributes,
        /// Tab headings and their content in source order.
        blocks: Vec<Block>,
        /// Range in the enclosing document.
        span: SourceSpan,
    },
    /// A semantic article container with an optional local anchor.
    Container {
        /// Presentation of the contained content.
        kind: DocumentContainerKind,
        /// Local anchor, when present.
        identifier: Option<String>,
        /// Contained document blocks.
        blocks: Vec<Block>,
        /// Range in the enclosing document.
        span: SourceSpan,
    },
    /// A display equation with an optional plain-text alternative.
    DisplayMath {
        /// Verbatim LaTeX source.
        latex: String,
        /// Author-supplied plain-text alternative.
        fallback: Option<String>,
        /// Full source range.
        span: SourceSpan,
    },
    /// Paragraph content.
    Paragraph {
        /// Inline children.
        inlines: Vec<Inline>,
        /// Full source range.
        span: SourceSpan,
    },
    /// Heading content.
    Heading {
        /// Heading level from one through six.
        level: usize,
        /// Heading attributes.
        attributes: Attributes,
        /// Inline heading children.
        inlines: Vec<Inline>,
        /// Full source range.
        span: SourceSpan,
    },
    /// Nested quotation.
    BlockQuote {
        /// Nested blocks.
        blocks: Vec<Block>,
        /// Full source range.
        span: SourceSpan,
    },
    /// Ordered, unordered, or task list.
    List {
        /// Whether the list uses ordered markers.
        ordered: bool,
        /// List items.
        items: Vec<ListItem>,
        /// Full source range.
        span: SourceSpan,
    },
    /// Thematic break.
    ThematicBreak {
        /// Full source range.
        span: SourceSpan,
    },
    /// Non-executable fenced code.
    CodeBlock {
        /// Optional language identifier.
        language: Option<String>,
        /// Code with container prefixes removed.
        source: String,
        /// Source segments used to construct `source`.
        source_segments: Vec<SourceSegment>,
        /// Full source range.
        span: SourceSpan,
    },
    /// Executable QMD cell, extracted but not executed.
    CodeCell(CodeCell),
    /// Pipe table.
    Table {
        /// Optional caption.
        caption: Vec<Inline>,
        /// Column alignments.
        alignments: Vec<TableAlignment>,
        /// Header and body rows.
        rows: Vec<TableRow>,
        /// Full source range.
        span: SourceSpan,
    },
    /// GFM alert or QMD callout.
    Callout {
        /// Callout category.
        kind: CalloutKind,
        /// Callout attributes.
        attributes: Attributes,
        /// Nested block content.
        blocks: Vec<Block>,
        /// Full source range.
        span: SourceSpan,
    },
    /// Retained syntax outside Diplodocus's supported documentation profiles.
    Unsupported {
        /// Source syntax-kind name.
        source_kind: String,
        /// Original source fragment, or empty when exact node ranges are unavailable.
        /// The enclosing sourced document retains the complete input.
        raw: String,
        /// Full source range.
        span: SourceSpan,
    },
}

/// A term and its explanatory content before conversion to document blocks.
#[derive(Clone)]
pub(crate) struct DescriptionEntry {
    pub term: Vec<Block>,
    pub description: Vec<Block>,
    pub span: SourceSpan,
}

impl Block {
    pub(crate) fn description_list(entries: Vec<DescriptionEntry>, span: SourceSpan) -> Self {
        Self::Container {
            kind: DocumentContainerKind::DefinitionList,
            identifier: None,
            blocks: entries
                .into_iter()
                .flat_map(|entry| {
                    [
                        Self::Container {
                            kind: DocumentContainerKind::DefinitionTerm,
                            identifier: None,
                            blocks: entry.term,
                            span: entry.span,
                        },
                        Self::Container {
                            kind: DocumentContainerKind::Definition,
                            identifier: None,
                            blocks: entry.description,
                            span: entry.span,
                        },
                    ]
                })
                .collect(),
            span,
        }
    }
}

/// Semantic containers shared by extracted documentation and articles.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum DocumentContainerKind {
    /// A disclosure whose first paragraph is its summary and remaining blocks are its body.
    Disclosure {
        /// Whether the disclosure is initially expanded in HTML.
        open: bool,
    },
    /// Terms and their definitions.
    DefinitionList,
    /// One definition-list term.
    DefinitionTerm,
    /// One definition-list body.
    Definition,
    /// An image or image group followed by caption content.
    Figure,
    /// The article's endnotes.
    Footnotes,
    /// One addressable endnote.
    Footnote,
    /// One addressable bibliography entry.
    BibliographyEntry,
    /// Inert content produced by one executable chunk.
    GeneratedChunk,
    /// Literal console output kept separate from its generating source.
    GeneratedOutput,
}

/// Inline formatting required by articles and citation styles.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum InlineStyle {
    /// Raised inline content.
    Superscript,
    /// Lowered inline content.
    Subscript,
    /// Small capital letters.
    SmallCaps,
}

/// One list item.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ListItem {
    /// Task state when the item has a checkbox.
    pub checked: Option<bool>,
    /// Nested block content.
    pub blocks: Vec<Block>,
    /// Full source range.
    pub span: SourceSpan,
}

/// One source segment of code after container framing is removed.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SourceSegment {
    /// Segment text.
    pub text: String,
    /// Exact range in the authored document.
    pub span: SourceSpan,
}

/// Extracted executable cell.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CodeCell {
    /// Optional engine or language name.
    pub language: Option<String>,
    /// Optional fenced-cell identifier.
    pub identifier: Option<SpannedString>,
    /// Cell classes in source order.
    pub classes: Vec<SpannedString>,
    /// Cell labels in source order.
    pub labels: Vec<SpannedString>,
    /// Executable code with hashpipe and container framing removed.
    pub source: String,
    /// Exact source segments used to construct `source`.
    pub source_segments: Vec<SourceSegment>,
    /// Every inline and hashpipe option declaration.
    pub options: Vec<CellOption>,
    /// Resolutions for canonical option keys.
    pub resolved_options: Vec<ResolvedCellOption>,
    /// Execution outputs in event order; absent for unexecuted authored cells.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub outputs: Vec<CellOutput>,
    /// Envelope around the executable source segments.
    pub code_span: Option<SourceSpan>,
    /// Full fenced-cell range.
    pub span: SourceSpan,
}

/// Origin of a cell-option declaration.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum CellOptionSource {
    /// Fence info string.
    InlineInfo,
    /// Hashpipe YAML preamble.
    HashpipeYaml,
}

/// One cell-option declaration, including overridden declarations.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CellOption {
    /// Original key spelling.
    pub key: Option<String>,
    /// Canonical lower-case, hyphenated key.
    pub canonical_key: Option<String>,
    /// Raw value spelling when present.
    pub raw_value: Option<String>,
    /// Cooked scalar value when the value is scalar.
    pub cooked_value: Option<String>,
    /// Structured YAML value for hashpipe declarations.
    pub value: Option<MetadataValue>,
    /// Declaration origin.
    pub source: CellOptionSource,
    /// Key range.
    pub key_span: Option<SourceSpan>,
    /// Value range.
    pub value_span: Option<SourceSpan>,
    /// Full declaration range.
    pub span: SourceSpan,
}

/// Resolution of one canonical cell-option key.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ResolvedCellOption {
    /// Canonical key.
    pub key: String,
    /// Winning declaration or ambiguity.
    pub resolution: CellOptionResolution,
}

/// Whether cell-option precedence selected one declaration.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum CellOptionResolution {
    /// One declaration won precedence.
    Resolved {
        /// Index into [`CodeCell::options`].
        declaration: usize,
    },
    /// Multiple declarations occur in the winning precedence tier.
    Ambiguous {
        /// Indices into [`CodeCell::options`].
        declarations: Vec<usize>,
    },
}

/// Pipe-table column alignment.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum TableAlignment {
    /// Renderer default.
    Default,
    /// Left aligned.
    Left,
    /// Centered.
    Center,
    /// Right aligned.
    Right,
}

/// One table row.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TableRow {
    /// Whether this is a header row.
    pub header: bool,
    /// Cells in source order.
    pub cells: Vec<TableCell>,
    /// Full source range.
    pub span: SourceSpan,
}

/// One table cell.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TableCell {
    /// Cell content as blocks.
    pub blocks: Vec<Block>,
    /// Full source range.
    pub span: SourceSpan,
}

/// Supported alert and callout category.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum CalloutKind {
    /// Informational note.
    Note,
    /// Helpful tip.
    Tip,
    /// Important information.
    Important,
    /// Warning.
    Warning,
    /// Caution.
    Caution,
}

/// Inline authored content.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum Inline {
    /// Additional semantic inline formatting.
    Styled {
        /// Requested formatting.
        style: InlineStyle,
        /// Inline children.
        inlines: Vec<Inline>,
        /// Range in the enclosing document.
        span: SourceSpan,
    },
    /// A citation whose formatted children are resolved from the bibliography.
    Citation {
        /// Original citation spelling.
        raw: String,
        /// Referenced bibliography keys in source order.
        keys: Vec<String>,
        /// Formatted, linked citation content.
        inlines: Vec<Inline>,
        /// Range in the enclosing document.
        span: SourceSpan,
    },
    /// An inline equation with an optional plain-text alternative.
    Math {
        /// Verbatim LaTeX source.
        latex: String,
        /// Author-supplied plain-text alternative.
        fallback: Option<String>,
        /// Full source range.
        span: SourceSpan,
    },
    /// Decoded text.
    Text {
        /// Decoded value.
        value: String,
        /// Source range.
        span: SourceSpan,
    },
    /// Collapsed whitespace.
    Space {
        /// Source range.
        span: SourceSpan,
    },
    /// Soft source line break.
    SoftBreak {
        /// Source range.
        span: SourceSpan,
    },
    /// Explicit hard line break.
    HardBreak {
        /// Source range.
        span: SourceSpan,
    },
    /// Nonbreaking space.
    NonbreakingSpace {
        /// Source range.
        span: SourceSpan,
    },
    /// Emphasized content.
    Emphasis {
        /// Nested content.
        inlines: Vec<Inline>,
        /// Full source range.
        span: SourceSpan,
    },
    /// Strongly emphasized content.
    Strong {
        /// Nested content.
        inlines: Vec<Inline>,
        /// Full source range.
        span: SourceSpan,
    },
    /// Struck-out content.
    Strikeout {
        /// Nested content.
        inlines: Vec<Inline>,
        /// Full source range.
        span: SourceSpan,
    },
    /// Inline code.
    Code {
        /// Literal code content.
        value: String,
        /// Full source range.
        span: SourceSpan,
    },
    /// Link.
    Link {
        /// Link label content.
        inlines: Vec<Inline>,
        /// Resolved target.
        target: String,
        /// Optional title.
        title: Option<String>,
        /// Link attributes.
        attributes: Attributes,
        /// Full source range.
        span: SourceSpan,
    },
    /// Image.
    Image {
        /// Alternative-text inlines.
        alt: Vec<Inline>,
        /// Resolved image target.
        target: String,
        /// Optional title.
        title: Option<String>,
        /// Image attributes.
        attributes: Attributes,
        /// Full source range.
        span: SourceSpan,
    },
    /// Automatic URL or email link.
    AutoLink {
        /// Target string.
        target: String,
        /// Full source range.
        span: SourceSpan,
    },
    /// Diplodocus's code-only unresolved-reference extension.
    SemanticReference {
        /// Package-qualified or unqualified semantic target.
        target: String,
        /// Full source range of the semantic reference.
        span: SourceSpan,
        /// Range of the code payload.
        target_span: SourceSpan,
    },
    /// Retained inline syntax outside the supported profile.
    Unsupported {
        /// Source syntax-kind name.
        source_kind: String,
        /// Original source fragment, or empty when exact node ranges are unavailable.
        /// The enclosing sourced document retains the complete input.
        raw: String,
        /// Full source range.
        span: SourceSpan,
    },
}