Skip to main content

euv_ui/component/markdown/view/
enum.rs

1use super::*;
2
3/// One block-level markdown node of the [`euv_markdown`] AST.
4///
5/// The tree is plain data so build tooling can generate it as `&'static`
6/// values and the renderer can walk it without allocations.
7#[derive(Clone, Copy, Debug)]
8pub enum EuvMdBlock {
9    /// `<h1>`–`<h6>`; `href` is the full permalink of the heading anchor.
10    Heading {
11        /// Heading level (1–6).
12        level: u8,
13        /// Slug id used for anchor scrolling.
14        id: &'static str,
15        /// Full permalink href.
16        href: &'static str,
17        /// Inline content.
18        inline: &'static [EuvMdInline],
19    },
20    /// A paragraph.
21    Paragraph(&'static [EuvMdInline]),
22    /// A fenced code block.
23    CodeBlock {
24        /// Fence info string (language).
25        lang: &'static str,
26        /// Raw code.
27        code: &'static str,
28    },
29    /// A block quote.
30    BlockQuote(&'static [EuvMdBlock]),
31    /// An ordered or unordered list.
32    List {
33        /// Ordered list flag.
34        ordered: bool,
35        /// List items.
36        items: &'static [&'static [EuvMdBlock]],
37    },
38    /// A GFM table.
39    Table {
40        /// Header cells.
41        head: &'static [&'static [EuvMdInline]],
42        /// Body rows.
43        rows: &'static [&'static [&'static [EuvMdInline]]],
44    },
45    /// A `:::` custom container.
46    Container {
47        /// Container kind (tip / warning / danger / …).
48        kind: &'static str,
49        /// Title label.
50        title: &'static str,
51        /// Inner blocks.
52        blocks: &'static [EuvMdBlock],
53    },
54    /// A thematic break (`<hr>`).
55    Rule,
56    /// A raw HTML block (escape hatch, rendered via `inner_html`).
57    Html(&'static str),
58}
59
60/// One inline markdown node of the [`euv_markdown`] AST.
61#[derive(Clone, Copy, Debug)]
62pub enum EuvMdInline {
63    /// Plain text.
64    Text(&'static str),
65    /// Bold.
66    Strong(&'static [EuvMdInline]),
67    /// Italic.
68    Em(&'static [EuvMdInline]),
69    /// Strikethrough.
70    Del(&'static [EuvMdInline]),
71    /// Inline code.
72    Code(&'static str),
73    /// A link (internal route or external URL).
74    Link {
75        /// Resolved href.
76        href: &'static str,
77        /// External link flag (opens in a new tab).
78        external: bool,
79        /// Link text.
80        children: &'static [EuvMdInline],
81    },
82    /// An image.
83    Image {
84        /// Image URL.
85        src: &'static str,
86        /// Alt text.
87        alt: &'static str,
88    },
89    /// A task-list checkbox marker.
90    TaskMarker(bool),
91    /// A soft line break.
92    SoftBreak,
93    /// A hard line break.
94    HardBreak,
95    /// Raw inline HTML (escape hatch).
96    Html(&'static str),
97}