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 diagram rendered to an inline SVG.
30    ///
31    /// The SVG is produced before the page data is generated — the
32    /// diagram engine is a build-time dependency of the generator, not
33    /// a runtime dependency of the browser bundle — so the browser only
34    /// ever carries the finished markup.
35    Diagram {
36        /// The inline SVG markup of the diagram.
37        svg: &'static str,
38    },
39    /// A block quote.
40    BlockQuote(&'static [EuvMdBlock]),
41    /// An ordered or unordered list.
42    List {
43        /// Ordered list flag.
44        ordered: bool,
45        /// List items.
46        items: &'static [&'static [EuvMdBlock]],
47    },
48    /// A GFM table.
49    Table {
50        /// Header cells.
51        head: &'static [&'static [EuvMdInline]],
52        /// Body rows.
53        rows: &'static [&'static [&'static [EuvMdInline]]],
54    },
55    /// A `:::` custom container.
56    Container {
57        /// Container kind (tip / warning / danger / …).
58        kind: &'static str,
59        /// Title label.
60        title: &'static str,
61        /// Inner blocks.
62        blocks: &'static [EuvMdBlock],
63    },
64    /// A thematic break (`<hr>`).
65    Rule,
66    /// A raw HTML block (escape hatch, rendered via `inner_html`).
67    Html(&'static str),
68}
69
70/// One inline markdown node of the [`euv_markdown`] AST.
71#[derive(Clone, Copy, Debug)]
72pub enum EuvMdInline {
73    /// Plain text.
74    Text(&'static str),
75    /// Bold.
76    Strong(&'static [EuvMdInline]),
77    /// Italic.
78    Em(&'static [EuvMdInline]),
79    /// Strikethrough.
80    Del(&'static [EuvMdInline]),
81    /// Inline code.
82    Code(&'static str),
83    /// A link (internal route or external URL).
84    Link {
85        /// Resolved href.
86        href: &'static str,
87        /// External link flag (opens in a new tab).
88        external: bool,
89        /// Link text.
90        children: &'static [EuvMdInline],
91    },
92    /// An image.
93    Image {
94        /// Image URL.
95        src: &'static str,
96        /// Alt text.
97        alt: &'static str,
98    },
99    /// A task-list checkbox marker.
100    TaskMarker(bool),
101    /// A soft line break.
102    SoftBreak,
103    /// A hard line break.
104    HardBreak,
105    /// Raw inline HTML (escape hatch).
106    Html(&'static str),
107}