Skip to main content

eure_mark/
document.rs

1//! Eumd document data structures
2
3use eure::ParseDocument;
4use eure_document::map::Map;
5
6/// Root document structure for `.eumd` files
7#[derive(Debug, Clone, PartialEq, ParseDocument)]
8#[eure(crate = ::eure::document)]
9pub struct EumdDocument {
10    /// Schema reference (extension field)
11    #[eure(ext, default)]
12    pub schema: Option<String>,
13
14    /// Document title (inline markdown)
15    pub title: String,
16
17    /// Document authors
18    #[eure(default)]
19    pub authors: Vec<Author>,
20
21    /// Publication/creation date
22    #[eure(default)]
23    pub date: Option<String>,
24
25    /// Categorization tags
26    #[eure(default)]
27    pub tags: Vec<String>,
28
29    /// Draft status
30    #[eure(default)]
31    pub draft: Option<bool>,
32
33    /// Document description/abstract (block markdown)
34    #[eure(default)]
35    pub description: Option<String>,
36
37    /// Bibliography in BibTeX format
38    #[eure(default)]
39    pub cites: Option<String>,
40
41    /// Footnote definitions
42    #[eure(default)]
43    pub footnotes: Map<String, Footnote>,
44
45    /// Introduction/preamble before first section
46    #[eure(default)]
47    pub intro: Option<String>,
48
49    /// Document sections (map with ID as key)
50    #[eure(default)]
51    pub sections: Map<String, Section>,
52}
53
54/// Author information
55#[derive(Debug, Clone, PartialEq, ParseDocument)]
56#[eure(crate = ::eure::document)]
57pub enum Author {
58    /// Detailed author information (try first due to more specific shape)
59    Detailed(DetailedAuthor),
60
61    /// Simple author name
62    Simple(String),
63}
64
65/// Detailed author information
66#[derive(Debug, Clone, PartialEq, ParseDocument)]
67#[eure(crate = ::eure::document)]
68pub struct DetailedAuthor {
69    pub name: String,
70    #[eure(default)]
71    pub affiliation: Option<String>,
72    #[eure(default)]
73    pub email: Option<String>,
74    #[eure(default)]
75    pub url: Option<String>,
76}
77
78/// Footnote definition
79#[derive(Debug, Clone, PartialEq, ParseDocument)]
80#[eure(crate = ::eure::document)]
81pub struct Footnote {
82    /// Footnote content (inline markdown)
83    pub content: String,
84}
85
86/// Section structure (recursive)
87#[derive(Debug, Clone, PartialEq, ParseDocument)]
88#[eure(crate = ::eure::document)]
89pub struct Section {
90    /// Section header (inline markdown). If omitted, section key is used.
91    #[eure(default)]
92    pub header: Option<String>,
93
94    /// Section body content (block markdown)
95    #[eure(default)]
96    pub body: Option<String>,
97
98    /// Nested subsections
99    #[eure(default)]
100    pub sections: Map<String, Section>,
101}
102
103impl EumdDocument {
104    /// Get the effective header for a section (uses key if header is None)
105    pub fn get_section_header<'a>(key: &'a str, section: &'a Section) -> &'a str {
106        section.header.as_deref().unwrap_or(key)
107    }
108}