Skip to main content

sim_codec_doc/
catalog.rs

1//! Public catalog of implemented and tracked markup backends.
2
3use crate::BackendId;
4
5/// Implementation state for a cataloged markup backend.
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub enum BackendStatus {
8    /// The backend is installed by the default registry and supports read/write.
9    Implemented,
10    /// The format is tracked by name, but no parser or writer is registered.
11    Tracked,
12    /// The format is tracked as an external-site-backed backend candidate.
13    ExternalSiteCandidate,
14}
15
16/// Catalog row describing one markup backend or tracked format.
17#[derive(Clone, Debug, PartialEq, Eq)]
18pub struct BackendInfo {
19    /// Stable backend id, used in `codec:markup/<id>` when implemented.
20    pub id: BackendId,
21    /// Implementation state for this backend.
22    pub status: BackendStatus,
23    /// Whether the default runtime can decode this backend.
24    pub can_read: bool,
25    /// Whether the default runtime can encode this backend.
26    pub can_write: bool,
27    /// Human-readable catalog note.
28    pub notes: &'static str,
29}
30
31/// Return the deterministic catalog of implemented and tracked markup backends.
32pub fn backend_catalog() -> Vec<BackendInfo> {
33    let mut catalog = vec![
34        implemented(
35            "asciidoc",
36            "Safe AsciiDoc read/write backend over asciidork-parser.",
37        ),
38        implemented(
39            "latex",
40            "Safe LaTeX article-subset backend over tree-sitter.",
41        ),
42        implemented(
43            "markdown",
44            "CommonMark/GFM-compatible Markdown read/write backend.",
45        ),
46        implemented("typst", "Safe Typst read/write backend over typst-syntax."),
47        external_candidate(
48            "texinfo",
49            "Texinfo is tracked as an external-site candidate; no local parser or texi2any site is registered.",
50        ),
51        tracked("bbcode", "Bulletin-board markup is tracked by name only."),
52        tracked("creole", "Creole wiki markup is tracked by name only."),
53        tracked("djot", "Djot is tracked by name only."),
54        tracked("myst", "MyST Markdown is tracked by name only."),
55        tracked("org", "Org markup is tracked by name only."),
56        tracked("rest", "reStructuredText is tracked by name only."),
57        tracked("textile", "Textile markup is tracked by name only."),
58        tracked("wikitext", "WikiText is tracked by name only."),
59    ];
60    catalog.sort_by(|left, right| left.id.cmp(&right.id));
61    catalog
62}
63
64fn implemented(id: &'static str, notes: &'static str) -> BackendInfo {
65    BackendInfo {
66        id: BackendId::new(id),
67        status: BackendStatus::Implemented,
68        can_read: true,
69        can_write: true,
70        notes,
71    }
72}
73
74fn tracked(id: &'static str, notes: &'static str) -> BackendInfo {
75    BackendInfo {
76        id: BackendId::new(id),
77        status: BackendStatus::Tracked,
78        can_read: false,
79        can_write: false,
80        notes,
81    }
82}
83
84fn external_candidate(id: &'static str, notes: &'static str) -> BackendInfo {
85    BackendInfo {
86        id: BackendId::new(id),
87        status: BackendStatus::ExternalSiteCandidate,
88        can_read: false,
89        can_write: false,
90        notes,
91    }
92}