use lex_extension::schema::{BodyKind, BodyPresence, BodyShape, Capabilities, HookSet, Schema};
use std::collections::BTreeMap;
pub const LEX_NOTES: &str = "lex.notes";
pub fn lex_notes_schema() -> Schema {
Schema {
schema_version: 1,
label: LEX_NOTES.into(),
description: Some(
"Marker annotation attached to a list whose items define footnotes. Items \
with numeric markers (1., 2., ...) define numbered footnotes referenced by \
`[1]`, `[2]`; items with labeled markers (`[^name]:`) define labeled \
footnotes referenced by `[^name]`. `lex.notes` may attach at the document \
root (footnotes visible globally) or inside a session (scoped to that \
session)."
.into(),
),
params: BTreeMap::new(),
attaches_to: vec!["list".into()],
body: BodyShape {
kind: BodyKind::None,
presence: BodyPresence::Optional,
description: Some(
"Marker annotation; no body. The list it attaches to carries the \
footnote definitions."
.into(),
),
},
verbatim_label: false,
capabilities: Capabilities::default(),
hooks: HookSet::default(),
handler: None,
}
}
pub fn all_schemas() -> Vec<Schema> {
vec![lex_notes_schema()]
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn notes_is_an_annotation_label() {
let schema = lex_notes_schema();
assert_eq!(schema.label, LEX_NOTES);
assert!(
!schema.verbatim_label,
"notes is an annotation, not verbatim"
);
assert_eq!(schema.attaches_to, vec!["list".to_string()]);
}
#[test]
fn notes_takes_no_body() {
let schema = lex_notes_schema();
assert_eq!(schema.body.kind, BodyKind::None);
assert_eq!(schema.body.presence, BodyPresence::Optional);
}
#[test]
fn notes_declares_no_hooks() {
let schema = lex_notes_schema();
assert!(!schema.hooks.resolve);
assert!(!schema.hooks.validate);
assert!(schema.hooks.render.is_empty());
}
#[test]
fn notes_schema_round_trips_through_json() {
let schema = lex_notes_schema();
let json = serde_json::to_string(&schema).expect("serialize");
let back: Schema = serde_json::from_str(&json).expect("deserialize");
assert_eq!(back, schema);
}
}