Skip to main content

euv_ui/component/markdown/
enum.rs

1use super::*;
2
3/// Pre-resolved syntax language used by the Eva code tokenizer without per-line string allocations.
4#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
5pub enum CodeLang {
6    /// Generic programming language syntax.
7    #[default]
8    Generic,
9    /// Rust source syntax (`"rust"`).
10    Rust,
11    /// Unified diff patch syntax (`"diff"`).
12    Diff,
13    /// JSON object/array syntax (`"json"`).
14    Json,
15    /// TOML key-value configuration syntax (`"toml"`).
16    Toml,
17    /// YAML key-value configuration syntax (`"yaml"`).
18    Yaml,
19}
20
21/// Sizing policy controlling how `EuvCodeBlock` expands or constrains its inline width and height.
22#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
23pub enum EuvCodeBlockSizeMode {
24    /// Automatically expands width and height to display the full code block without cramped fixed-height clipping while staying bounded inside constrained parent cards or viewports with smooth horizontal scrolling.
25    #[default]
26    AutoExpand,
27    /// Expands height automatically to show all lines without vertical clipping while constraining width to the parent container with full-area horizontal scrolling.
28    AutoExpandHeight,
29    /// Expands width naturally to the longest code line while constraining height (`max_height`) with full-area vertical scrolling.
30    AutoExpandWidth,
31    /// Constrains both width and height (`max_height`) with full-area 2D horizontal and vertical scrolling.
32    Fixed,
33}
34
35/// Syntax token classification mapped directly to VS Code `Eva Light Bold` / `Eva Dark Bold` TextMate scopes.
36#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
37pub enum CodeTokenKind {
38    /// Default editor foreground text.
39    #[default]
40    Plain,
41    /// Storage keyword or modifier (`fn`, `let`, `mut`, `pub`, `struct`; `#7C4DFF` / `#A78CFA` bold).
42    Keyword,
43    /// Control-flow or module keyword (`if`, `match`, `return`, `use`, `where`; `#C838C6` / `#CF68E1` bold).
44    Control,
45    /// Symbolic operator (`=`, `->`, `=>`, `&`, `+`, `-`; `#00BEC4` / `#56B7C3`).
46    Operator,
47    /// User type, struct, enum, or trait identifier (`#00BEC4` / `#56B7C3`).
48    Type,
49    /// Built-in primitive or numeric type (`u32`, `f32`, `bool`, `str`; `#EF8ED8` / `#FF6AB3`).
50    PrimitiveType,
51    /// Function or method name (`#437AED` / `#6495EE` bold).
52    Function,
53    /// Macro invocation, attribute, or lifetime (`#437AED` / `#6495EE` bold).
54    Macro,
55    /// Quoted string or character literal (`#53A053` / `#98C379`).
56    String,
57    /// Numeric literal (`#FF6D12` / `#FF9070`).
58    Number,
59    /// Language constant (`true`, `false`, `None`, `Some`; `#C838C6` / `#CF68E1` bold).
60    Constant,
61    /// Line or block comment (`#A9A9AA` / `#676E95` italic).
62    Comment,
63    /// Property key, field, or `Result`/`Option` type (`#CD6069` / `#E06C75`).
64    Property,
65    /// Punctuation or delimiter (`#A0A1A7` / `#79859D`).
66    Punctuation,
67    /// Diff insertion line (`+...`, `#44C145` / `#4EC150`).
68    DiffAdd,
69    /// Diff deletion line (`-...`, `#F14C4C`).
70    DiffDel,
71}
72
73/// Semantic variant for `EuvMarkdownQuote` supporting plain blockquotes and GitHub-flavored Alerts.
74#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
75pub enum EuvMarkdownAlertKind {
76    /// Standard Markdown blockquote (`> ...`).
77    #[default]
78    Quote,
79    /// Informational note alert (`> [!NOTE]`).
80    Note,
81    /// Helpful tip alert (`> [!TIP]`).
82    Tip,
83    /// Essential requirement alert (`> [!IMPORTANT]`).
84    Important,
85    /// Warning alert (`> [!WARNING]`).
86    Warning,
87    /// Critical caution alert (`> [!CAUTION]`).
88    Caution,
89}
90
91/// Column alignment parsed from GFM Markdown tables.
92#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
93pub enum EuvMarkdownAlign {
94    /// Left-aligned column (`:---`).
95    #[default]
96    Left,
97    /// Center-aligned column (`:---:`).
98    Center,
99    /// Right-aligned column (`---:`).
100    Right,
101}
102
103/// Inline emphasis wrapper mode applied when recursively flattening nested Markdown inline spans.
104#[derive(Clone, Copy, Debug, Eq, PartialEq)]
105pub(crate) enum InlineWrapStyle {
106    /// Wrap inner text spans as bold.
107    Bold,
108    /// Wrap inner text spans as italic.
109    Italic,
110    /// Wrap inner text spans as combined bold and italic.
111    BoldItalic,
112    /// Wrap inner text spans with strikethrough.
113    Strike,
114    /// Wrap inner text spans as highlighted text.
115    Highlight,
116}
117
118/// Parsed inline Markdown segment rendered inside `EuvMarkdownParagraph` and list items.
119#[derive(Clone, Debug, Eq, PartialEq)]
120pub enum EuvMarkdownInline {
121    /// Plain body text span.
122    Text(String),
123    /// Bold emphasis (`**text**` or `__text__`).
124    Bold(String),
125    /// Italic emphasis (`*text*` or `_text_`).
126    Italic(String),
127    /// Combined bold and italic emphasis (`***text***`).
128    BoldItalic(String),
129    /// Strikethrough (`~~text~~`).
130    Strike(String),
131    /// Highlighted text (`==text==` or `<mark>text</mark>`).
132    Highlight(String),
133    /// Superscript text (`^text^` or `<sup>text</sup>`).
134    Superscript(String),
135    /// Subscript text (`~text~` or `<sub>text</sub>`).
136    Subscript(String),
137    /// Inline monospace code chip (`` `code` ``).
138    Code(String),
139    /// Inline math expression (`$expr$`) formatted with Unicode math symbols.
140    Math(String),
141    /// Inline footnote reference badge (`[^id]`).
142    FootnoteRef(String),
143    /// Inline image (`![alt](url)` or `<img src="..." alt="...">`).
144    Image {
145        /// Accessible alt caption.
146        alt: String,
147        /// Image source URI.
148        url: String,
149    },
150    /// Clickable linked image or badge (`[![alt](image_url)](link_url)`).
151    LinkedImage {
152        /// Accessible alt caption.
153        alt: String,
154        /// Image source URI.
155        image_url: String,
156        /// Destination hyperlink URL.
157        link_url: String,
158    },
159    /// Clickable hyperlink (`[label](url)`, `[label][ref]`, or `<https://...>`).
160    Link {
161        /// Visible anchor text.
162        label: String,
163        /// Target URL or route.
164        url: String,
165    },
166    /// Keyboard shortcut cap (`<kbd>Cmd+K</kbd>`).
167    Kbd(String),
168    /// Explicit inline hard line break (`  \n` or `\\\n`).
169    HardBreak,
170}
171
172/// Parsed block-level Markdown AST node rendered natively by `EuvMarkdown`.
173#[derive(Clone, Debug, Eq, PartialEq)]
174pub enum EuvMarkdownBlock {
175    /// ATX heading (`#` through `######`).
176    Heading {
177        /// Heading level (`1..=6`).
178        level: u8,
179        /// Heading text.
180        text: String,
181    },
182    /// Rich inline paragraph.
183    Paragraph(Vec<EuvMarkdownInline>),
184    /// Fenced or indented syntax-highlighted code block.
185    CodeBlock {
186        /// Language identifier (e.g. `"rust"`, `"ts"`, `"json"`).
187        language: String,
188        /// Optional code fence header title or filename (`title="..."` / `filename="..."`).
189        title: Option<String>,
190        /// Optional 1-based highlighted line numbers parsed from `{1,3-5}` fence markers.
191        highlight_lines: Vec<usize>,
192        /// Raw code body.
193        code: String,
194    },
195    /// Native vector Mermaid diagram block (` ```mermaid `).
196    Mermaid {
197        /// Raw Mermaid diagram source text.
198        source: String,
199    },
200    /// Embedded native vector ECharts block (` ```echart ` or ` ```echarts `).
201    EChart {
202        /// Raw JSON or key-value ECharts specification text.
203        source: String,
204    },
205    /// Display math block (`$$...$$`).
206    MathBlock(String),
207    /// Blockquote or GitHub-flavored Alert / container callout.
208    Quote {
209        /// Plain quote or alert kind.
210        kind: EuvMarkdownAlertKind,
211        /// Optional custom callout header title (for example from `::: warning Custom Title`).
212        title: Option<String>,
213        /// Nesting depth (`1` = top level).
214        depth: usize,
215        /// Raw content lines inside the callout.
216        lines: Vec<String>,
217        /// Recursively parsed nested Markdown child blocks inside the callout.
218        children: Vec<EuvMarkdownBlock>,
219    },
220    /// Unordered, ordered, nested, or task-checklist list.
221    List {
222        /// Whether items render with ordinal numbers.
223        ordered: bool,
224        /// Starting ordinal number for ordered lists (`1` by default).
225        start: usize,
226        /// Ordered list items.
227        items: Vec<EuvMarkdownListItem>,
228    },
229    /// GFM aligned data table.
230    Table {
231        /// Column header labels.
232        headers: Vec<String>,
233        /// Column alignments.
234        alignments: Vec<EuvMarkdownAlign>,
235        /// Body rows.
236        rows: Vec<Vec<String>>,
237    },
238    /// Extended Markdown definition list (`Term` + `: Definition`).
239    DefinitionList(Vec<EuvMarkdownDefItem>),
240    /// Bottom footnote definitions section (`[^id]: text`).
241    Footnotes(Vec<EuvMarkdownFootnote>),
242    /// Thematic horizontal divider (`---`).
243    Divider,
244    /// Image figure (`![alt](url)`).
245    Image {
246        /// Accessible caption / alt text.
247        alt: String,
248        /// Image source URI or asset path.
249        url: String,
250    },
251    /// Collapsible `<details><summary>` or `::: details` disclosure block.
252    Details {
253        /// Toggle summary header.
254        summary: String,
255        /// Whether the disclosure block starts expanded (`<details open>`).
256        open: bool,
257        /// Raw content lines revealed when expanded.
258        body: Vec<String>,
259        /// Recursively parsed nested Markdown child blocks revealed when expanded.
260        children: Vec<EuvMarkdownBlock>,
261    },
262}