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