### Run Basic Markdown Rendering Example Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/README.md Execute the 'basic' example to see minimal markdown rendering. ```bash cargo run --example basic ``` -------------------------------- ### Run Mermaid Diagram Rendering Example Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/README.md Run the 'mermaid' example to demonstrate the rendering of Mermaid diagrams. ```bash cargo run --example mermaid ``` -------------------------------- ### Run Syntax-Highlighted Code Blocks Example Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/README.md Run the 'code' example with the 'highlight-lang-all' feature enabled to demonstrate syntax-highlighted code blocks. ```bash cargo run --example code --features highlight-lang-all ``` -------------------------------- ### Run Image Embedding Example Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/README.md Execute the 'image' example to test image embedding and zoom functionality. ```bash cargo run --example image ``` -------------------------------- ### Run Collapsible Tree View Example Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/README.md Execute the 'tree_list' example to showcase the collapsible JSON/TOML tree view. ```bash cargo run --example tree_list ``` -------------------------------- ### Run ratatui-markdown examples Source: https://github.com/celestia-island/ratatui-markdown/blob/master/README.md Execute the provided examples using cargo run. Specific features like syntax highlighting require additional feature flags. ```bash cargo run --example basic ``` ```bash cargo run --example code --features highlight-lang-all ``` ```bash cargo run --example image ``` ```bash cargo run --example mermaid ``` ```bash cargo run --example tree_list ``` -------------------------------- ### HybridScrollView Example Usage Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/scroll.md Demonstrates how to initialize and use the `HybridScrollView` with focusable regions, including setting content, scrolling, and navigating through items. ```rust use ratatui_markdown::scroll::{HybridScrollView, FocusableItemRange, FocusableRegion}; let mut scroll = HybridScrollView::new() .with_cursor_indicator(true); // Content lines let lines: Vec = (0..100) .map(|i| Line::raw(format!("Line {}", i))) .collect(); // Make lines 30-32 focusable let region = FocusableRegion { items: vec![ FocusableItemRange { start_line: 30, end_line: 31, id: "item-a".into() }, FocusableItemRange { start_line: 31, end_line: 32, id: "item-b".into() }, FocusableItemRange { start_line: 32, end_line: 33, id: "item-c".into() }, ], }; scroll.set_content(lines, vec![region]); // Free-scroll down; auto-engages when line 30 enters viewport center scroll.scroll_down(); // Navigate through items while scroll.scroll_down() == InputResult::Continue { if let Some(id) = scroll.selected_item_id() { println!("Selected: {}", id); } } ``` -------------------------------- ### Complete Markdown Parsing and Rendering Example Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/markdown.md Demonstrates the usage of MarkdownRenderer to parse a markdown string and render it into ratatui Lines. This example includes headings, paragraphs with inline formatting, code blocks, and tables. ```rust use ratatui_markdown::markdown::MarkdownRenderer; let md = r#"# # Title This is a paragraph with **bold** and *italic* text. ## Code ```rust fn main() { println!("Hello!"); } ``` | Name | Version | |------|---------| | ratatui | 0.29 | | serde | 1.0 | "#; let renderer = MarkdownRenderer::new(80); let blocks = renderer.parse(md); let lines = renderer.render(&blocks, theme); // use lines in a ratatui widget ``` -------------------------------- ### Full CollapsibleTree Example Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Demonstrates parsing TOML content, expanding all nodes, rendering the tree, collapsing a specific subtree, and retrieving focusable items for navigation. ```rust use ratatui_markdown::tree::CollapsibleTree; let toml_content = r#"# [package] name = "my-app" version = "0.1.0" [dependencies] ratatui = "0.29" serde = { version = "1.0", features = ["derive"] } [features] default = ["std"] std = [] #"#; let mut tree = CollapsibleTree::from_toml_str(toml_content).unwrap(); // Expand everything tree.expand_all(); // Render to lines let lines = tree.render_lines(80, theme); // Collapse the dependencies subtree tree.toggle("dependencies"); // Re-render — dependencies are now collapsed let lines = tree.render_lines(80, theme); // Get focusable items for scroll navigation let items = tree.build_focusable_items(); ``` -------------------------------- ### CollapsibleTree Manipulation Examples Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Demonstrates toggling nodes using slash-separated paths, expanding/collapsing all nodes, and handling toggles within a scroll context. ```rust // Toggle using a slash-separated path tree.toggle("dependencies"); // toggle root key tree.toggle("dependencies/serde"); // toggle nested key // Convenience methods tree.expand_all(); tree.collapse_all(); tree.expand_to_depth(2); // In a scroll context — uses the selected item's ID if scroll.selected_item_id().is_some() { tree.handle_toggle(selected_id); } ``` -------------------------------- ### Render Markdown Preview in Ratatui App Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/preview.md Example of how to render the MarkdownPreview component within a ratatui application's UI rendering function. ```rust // In your ratatui app's render function: fn render_ui(f: &mut ratatui::Frame, preview: &mut MarkdownPreview, theme: &impl RichTextTheme) { preview.render(f, f.area(), f.area(), theme); } ``` -------------------------------- ### Implementing AppTheme with RichTextTheme Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/theme.md Example implementation of the `RichTextTheme` trait for an `AppTheme` struct. Demonstrates how to toggle dark mode and update the generation token to invalidate the cache. ```rust struct AppTheme { generation: Generation, dark_mode: bool, } impl RichTextTheme for AppTheme { fn generation(&self) -> Generation { self.generation } fn get_text_color(&self) -> Color { if self.dark_mode { Color::White } else { Color::Black } } // ... } impl AppTheme { fn toggle_dark_mode(&mut self) { self.dark_mode = !self.dark_mode; self.generation = self.generation.next(); } } ``` -------------------------------- ### Conditional Compilation for Features Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/contributing.md Example of using conditional compilation with Rust's cfg attribute to gate code based on feature flags. ```rust #[cfg(feature = "markdown")] pub mod markdown; ``` -------------------------------- ### TOML Frontmatter Stripping Example Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/preview.md When enabled, content delimited by '+++' is treated as TOML frontmatter and stripped before rendering. Only the content after the frontmatter is displayed. ```markdown +++ title = "My Document" author = "Jane Doe" +++ # Actual Content This is the body. ``` -------------------------------- ### Implement Custom Theme with Color Slots Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/theme.md Implement the `RichTextTheme` trait to define custom colors for different elements like text, backgrounds, borders, and JSON components. This example shows a Catppuccin Mocha theme implementation. ```rust use ratatui::style::Color; use ratatui_markdown::theme::{Generation, RichTextTheme}; struct CatppuccinMocha; impl RichTextTheme for CatppuccinMocha { fn generation(&self) -> Generation { Generation(0) } fn get_text_color(&self) -> Color { Color::new(205, 214, 244) } // text fn get_muted_text_color(&self) -> Color { Color::new(147, 153, 178) } // overlay2 fn get_background_color(&self) -> Color { Color::new(30, 30, 46) } // base fn get_primary_color(&self) -> Color { Color::new(137, 180, 250) } // blue fn get_secondary_color(&self) -> Color { Color::new(203, 166, 247) } // mauve fn get_info_color(&self) -> Color { Color::new(137, 220, 235) } // sky fn get_border_color(&self) -> Color { Color::new(69, 71, 90) } // surface1 fn get_focused_border_color(&self) -> Color { Color::new(137, 180, 250) } // blue fn get_popup_selected_background(&self) -> Color { Color::new(69, 71, 90) } fn get_popup_selected_text_color(&self) -> Color { Color::new(205, 214, 244) } fn get_json_key_color(&self) -> Color { Color::new(137, 220, 235) } // sky fn get_json_string_color(&self) -> Color { Color::new(166, 227, 161) } // green fn get_json_number_color(&self) -> Color { Color::new(250, 179, 135) } // peach fn get_json_bool_color(&self) -> Color { Color::new(203, 166, 247) } // mauve fn get_json_null_color(&self) -> Color { Color::new(108, 112, 134) } // surface2 fn get_accent_yellow(&self) -> Color { Color::new(249, 226, 175) } // yellow } ``` -------------------------------- ### Initialize and Configure Markdown Preview Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/preview.md Set up a new MarkdownPreview instance, configure frontmatter stripping and padding, and load markdown content with TOML frontmatter. Also demonstrates setting a collapsible tree and action items. ```rust use ratatui_markdown::preview::{MarkdownPreview, ActionItem}; use ratatui_markdown::tree::CollapsibleTree; let mut preview = MarkdownPreview::new() .with_strip_frontmatter(true) .with_left_padding(true); // Set markdown content (with TOML frontmatter) preview.set_content(concat!( "+++\n", "title = \"My Doc\"\n", "+++\n", "\n", "# Hello\n\nContent here.\n", )); // Set a tree let tree = CollapsibleTree::from_json_str(r#"{"config": {"theme": "dark"}}"#).unwrap(); preview.set_tree(Some(tree)); // Set action items preview.set_action_items(vec![ ActionItem { id: "edit".into(), label: " Edit ".into() }, ActionItem { id: "save".into(), label: " Save ".into() }, ]); ``` -------------------------------- ### Clone Repository and Build Project Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/contributing.md Clone the ratatui-markdown repository and build the project using Cargo. ```bash git clone https://github.com/celestia-island/ratatui-markdown.git cd ratatui-markdown cargo build ``` -------------------------------- ### Release Process: Tagging and Pushing Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/contributing.md Steps to release a new version by bumping the version in Cargo.toml, creating a Git tag, and pushing the tag. ```bash # Bump version in Cargo.toml, then: git tag v0.1.1 git push origin v0.1.1 ``` -------------------------------- ### Initialize and Configure TextInput Component Source: https://github.com/celestia-island/ratatui-markdown/blob/master/PLAN.md Demonstrates how to create and configure a TextInput component with various styles and behaviors. Use this to set up a text input field for editing or displaying text within a TUI application. ```rust let mut input = TextInput::new() .with_mode(InputMode::Edit) .with_cursor_style(CursorStyle::new().with_shape(CursorShape::Bar)) .with_blink_controller(Rc::new(my_blink_controller)) .with_password(false) .with_placeholder("type here...") .with_max_width(80); input.set_text("# Hello **world**"); input.set_cursor_char_idx(5); input.render(f, area, &theme); ``` -------------------------------- ### Handle User Input for Markdown Preview Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/preview.md Demonstrates how to handle keyboard input to control scrolling, tree node expansion, and other interactions within the MarkdownPreview component. ```rust // Handle input fn handle_input(key: rataui::crossterm::event::KeyCode, preview: &mut MarkdownPreview) { match key { KeyCode::Up | KeyCode::Char('k') => preview.scroll_up(), KeyCode::Down | KeyCode::Char('j') => preview.scroll_down(), KeyCode::PageUp => preview.page_up(20), KeyCode::PageDown => preview.page_down(20), KeyCode::Home => preview.scroll_to_top(), KeyCode::End => preview.scroll_to_bottom(), KeyCode::Enter => { preview.toggle_tree_node(); } _ => {} } } ``` -------------------------------- ### Run All Tests Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/contributing.md Command to run all tests in the project, including those for all enabled features. ```bash cargo test --all-features ``` -------------------------------- ### Set Action Items for Markdown Preview Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/preview.md Define keyboard-selectable options at the bottom of the view. Action item IDs are prefixed with `action:` internally. ```rust preview.set_action_items(vec![ ActionItem { id: "confirm".into(), label: " Confirm ".into() }, ActionItem { id: "cancel".into(), label: " Cancel ".into() }, ]); // In your input handler: if let Some("confirm") = preview.selected_action_id() { // handle confirm } ``` -------------------------------- ### Feature Dependencies in Cargo.toml Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/contributing.md Illustrates how to define feature dependencies in the Cargo.toml file. ```toml tree = ["dep:serde_json", "dep:toml", "scroll"] preview = ["markdown", "scroll", "tree"] ``` -------------------------------- ### Add ratatui-markdown to Dependencies Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/README.md Add the ratatui-markdown crate to your Cargo.toml file for basic usage. ```toml [dependencies] ratatui-markdown = "0.3" ``` -------------------------------- ### Enable Full Feature Set for ratatui-markdown Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/README.md To enable the full feature set of ratatui-markdown, including the preview functionality, specify it in your Cargo.toml. ```toml [dependencies] ratatui-markdown = { version = "0.3", features = ["preview"] } ``` -------------------------------- ### Test Specific Feature Combinations Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/contributing.md Commands to test the project with different combinations of feature flags, excluding default features. ```bash cargo test --no-default-features cargo test --no-default-features --features markdown cargo test --no-default-features --features scroll cargo test --no-default-features --features tree cargo test --no-default-features --features mermaid cargo test --no-default-features --features image cargo test --no-default-features --features viewer cargo test --no-default-features --features preview # implies markdown, scroll, tree ``` -------------------------------- ### Add ratatui-markdown to Cargo.toml Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/getting-started.md Include this in your Cargo.toml to add the ratatui-markdown library with all features enabled by default. ```toml [dependencies] ratatui-markdown = "0.1" ``` -------------------------------- ### Enable Selective Features in Cargo.toml Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/getting-started.md To reduce compile time and dependencies, specify only the features you need in your Cargo.toml. ```toml # Markdown rendering only ratatui-markdown = { version = "0.1", default-features = false, features = ["markdown"] } ``` ```toml # Scroll system only ratatui-markdown = { version = "0.1", default-features = false, features = ["scroll"] } ``` ```toml # Tree view (pulls in scroll, serde_json, and toml) ratatui-markdown = { version = "0.1", default-features = false, features = ["tree"] } ``` -------------------------------- ### Add ratatui-markdown to Cargo.toml Source: https://github.com/celestia-island/ratatui-markdown/blob/master/README.md Include the ratatui-markdown crate as a dependency in your project's Cargo.toml file. For the full feature set, enable the 'preview' feature. ```toml [dependencies] ratatui-markdown = "0.3" ``` ```toml [dependencies] ratatui-markdown = { version = "0.3", features = ["preview"] } ``` -------------------------------- ### Configure SpanTree with Cursor Line Mode Source: https://github.com/celestia-island/ratatui-markdown/blob/master/PLAN.md Shows how to initialize a SpanTree with a specific cursor line mode. This is useful for controlling how the cursor is displayed across multiple lines in a scrollable list or tree structure. ```rust let tree = SpanTree::new() .with_cursor_line_mode(CursorLineMode::AllLines); ``` -------------------------------- ### Use the MarkdownPreview Widget Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/getting-started.md The MarkdownPreview widget provides a scrollable view for markdown content, optionally with a collapsible tree. It handles scrolling, node toggling, and rendering. ```rust use ratatui_markdown::preview::MarkdownPreview; use ratatui_markdown::theme::RichTextTheme; let mut preview = MarkdownPreview::new() .with_left_padding(true); // Set markdown content preview.set_content("# Welcome\n\n- Item one\n- Item two\n\n```rust\nlet x = 42; ```"); // Set a collapsible tree (optional) let tree = CollapsibleTree::from_json_str(r#"{"config": {"port": 8080}}"#).unwrap(); preview.set_tree(Some(tree)); // Handle keyboard input preview.scroll_up(); preview.scroll_down(); preview.page_up(10); preview.page_down(10); preview.toggle_tree_node(); // Enter key // Render in your ratatui draw loop fn draw(f: &mut ratatui::Frame, preview: &mut MarkdownPreview, theme: &impl RichTextTheme) { preview.render(f, f.area(), f.area(), theme); } ``` -------------------------------- ### CollapsibleTree Constructors Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Constructs a CollapsibleTree from various input formats. `from_json_str` and `from_toml_str` parse string inputs, while `from_value` builds from an existing `serde_json::Value`. ```APIDOC ## CollapsibleTree Constructors ### `from_json_str` Parses a JSON string into a tree. Keys use `KeyStyle::Json` (quoted, with `:` separator). ### `from_toml_str` Parses a TOML string (converts internally to JSON). Keys use `KeyStyle::Toml` (unquoted, with `=` separator). ### `from_value` Builds a tree from an existing `serde_json::Value` with a chosen key style. ``` -------------------------------- ### MarkdownPreview Widget API Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/preview.md Defines the structure for ActionItem and the methods available for the MarkdownPreview widget, including configuration, content management, tree manipulation, action item handling, navigation, state retrieval, and rendering. ```rust pub struct ActionItem { pub id: String, pub label: String, } impl MarkdownPreview { pub fn new() -> Self; // Configuration pub fn with_strip_frontmatter(self, strip: bool) -> Self; pub fn with_left_padding(self, padding: bool) -> Self; // Content pub fn set_content(&mut self, content: &str); pub fn clear(&mut self); pub fn is_empty(&self) -> bool; // Tree pub fn set_tree(&mut self, tree: Option); pub fn tree_mut(&mut self) -> Option<&mut CollapsibleTree>; pub fn has_tree(&self) -> bool; pub fn toggle_tree_node(&mut self) -> bool; // Action items pub fn set_action_items(&mut self, items: Vec); pub fn selected_action_id(&self) -> Option<&str>; // Navigation pub fn scroll_up(&mut self); pub fn scroll_down(&mut self); pub fn scroll_to_top(&mut self); pub fn scroll_to_bottom(&mut self); pub fn page_up(&mut self, lines: usize); pub fn page_down(&mut self, lines: usize); // State pub fn total_lines(&self) -> usize; pub fn scroll_offset(&self) -> usize; pub fn visible_height(&self) -> usize; pub fn is_engaged(&self) -> bool; pub fn engaged_cursor(&self) -> Option<(usize, usize)>; pub fn selected_item_id(&self) -> Option<&str>; // Rendering pub fn render(&mut self, f: &mut Frame, inner_area: Rect, outer_area: Rect, theme: &impl RichTextTheme); } ``` -------------------------------- ### Run All CI Checks Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/contributing.md Execute all Cargo tests, formatting checks, and clippy lints to ensure code quality and consistency. ```bash cargo test --all-features cargo fmt --all -- --check cargo clippy --all-features -- -D warnings cargo test --no-default-features cargo test --no-default-features --features markdown cargo test --no-default-features --features scroll cargo test --no-default-features --features tree ``` -------------------------------- ### Render Markdown Text Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/getting-started.md Use MarkdownRenderer to parse markdown strings into blocks and then render them into ratatui Lines. Ensure you have a RichTextTheme defined. ```rust use ratatui_markdown::markdown::MarkdownRenderer; use ratatui_markdown::theme::RichTextTheme; // Create a renderer with maximum content width let renderer = MarkdownRenderer::new(80); // Parse markdown text into blocks let blocks = renderer.parse("# Hello\n\nThis is **bold** and *italic* text."); // Render blocks into ratatui::text::Line<'static> let lines = renderer.render(&blocks, &my_theme); ``` -------------------------------- ### CollapsibleTree Rendering Methods Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Provides methods for rendering the tree into lines, flattening its visible entries, and building focusable item ranges for UI integration. ```rust // Rendering pub fn render_lines(&self, width: usize, theme: &impl RichTextTheme) -> Vec>; pub fn flatten(&self) -> Vec; pub fn build_focusable_items(&self) -> Vec; ``` -------------------------------- ### Configure Feature Flags for ratatui-markdown Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/index.md Customize your ratatui-markdown integration by disabling default features and enabling only the specific features you need in your Cargo.toml. ```toml [dependencies] ratatui-markdown = { version = "0.3", default-features = false, features = ["markdown"] } ``` -------------------------------- ### CollapsibleTree Constructors Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Parses JSON or TOML strings into a CollapsibleTree, or builds one from an existing serde_json::Value with a specified key style. ```rust // Constructors pub fn from_json_str(json: &str) -> Result; pub fn from_toml_str(toml: &str) -> Result>; pub fn from_value(value: serde_json::Value, style: KeyStyle) -> Self; ``` -------------------------------- ### Browse a Collapsible Tree from JSON Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/getting-started.md Parse a JSON string into a CollapsibleTree, render its lines, and build focusable items for navigation. You can also toggle nodes to expand or collapse them. ```rust use ratatui_markdown::tree::CollapsibleTree; // Parse JSON into a collapsible tree let json_str = r#"{"name": "project", "deps": {"ratatui": "0.29", "serde": "1.0"}}"#; let mut tree = CollapsibleTree::from_json_str(json_str).unwrap(); // Render tree lines let lines = tree.render_lines(80, &my_theme); // Get focusable items for navigation let items = tree.build_focusable_items(); // Toggle a node tree.toggle("deps/serde"); ``` -------------------------------- ### Tree Line Helpers Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Low-level functions for constructing individual lines within the tree view, providing fine-grained control over appearance. ```APIDOC ## Tree Line Helpers ### `make_body_line` Constructs a line for the main content of a tree entry, including key and value. ### `make_status_line` Constructs a line for status messages within the tree view. ### `make_branch_dispatch_line` Constructs a line representing the branch status (expanded, collapsed, or leaf node). ``` -------------------------------- ### CollapsibleTree Rendering Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Methods for rendering the tree into different formats for display and integration with other UI components. ```APIDOC ## CollapsibleTree Rendering ### `render_lines` Produces styled `Line`s with tree connectors and colored values, suitable for rendering in a terminal. ### `flatten` Returns a flat list of all currently visible entries, respecting the collapsed state of nodes. ### `build_focusable_items` Returns focusable ranges for integration with components like `HybridScrollView`. The IDs generated match the tree paths. ``` -------------------------------- ### FocusableItemRange and FocusableRegion Definitions Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/scroll.md Defines the structures for `FocusableItemRange` and `FocusableRegion`, used to specify which lines in the content are interactive and can be navigated. ```rust pub struct FocusableItemRange { pub start_line: usize, // inclusive pub end_line: usize, // exclusive pub id: String, // unique identifier } pub struct FocusableRegion { pub items: Vec, } ``` -------------------------------- ### KeyStyle Enum Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Specifies the style for displaying keys in the tree: Json (quoted, with ':') or Toml (unquoted, with '='). ```rust pub enum KeyStyle { Json, // "key": value Toml, // key = value } ``` -------------------------------- ### CollapsibleTree Structure and Methods Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Defines the CollapsibleTree struct and its core methods for parsing, manipulation, and rendering. Requires the 'tree' feature flag. ```rust pub struct CollapsibleTree { /* fields */ } impl CollapsibleTree { // Constructors pub fn from_json_str(json: &str) -> Result; pub fn from_toml_str(toml: &str) -> Result>; pub fn from_value(value: serde_json::Value, style: KeyStyle) -> Self; // Tree manipulation pub fn toggle(&mut self, path: &str) -> bool; pub fn handle_toggle(&mut self, id: &str) -> bool; pub fn expand_all(&mut self); pub fn collapse_all(&mut self); pub fn expand_to_depth(&mut self, depth: usize); // Rendering pub fn render_lines(&self, width: usize, theme: &impl RichTextTheme) -> Vec>; pub fn flatten(&self) -> Vec; pub fn build_focusable_items(&self) -> Vec; } ``` -------------------------------- ### Tree Line Helper Functions Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Provides low-level functions for constructing different types of lines within the tree view, such as body lines, status lines, and branch dispatch lines. ```rust pub fn make_body_line(key: &str, value: &str, style: &Style, value_style: &Style) -> Line<'static>; pub fn make_status_line(status: &str, style: &Style) -> Line<'static>; pub fn make_branch_dispatch_line(kind: EntryKind, ...) -> Line<'static>; ``` -------------------------------- ### MarkdownPreview Widget API Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/preview.md The MarkdownPreview widget provides a comprehensive set of methods for managing and interacting with its content, tree structure, and action items. ```APIDOC ## MarkdownPreview ### Description Provides methods for creating, configuring, and managing the MarkdownPreview widget. ### Methods - **`new()`**: Creates a new instance of `MarkdownPreview`. - **`with_strip_frontmatter(self, strip: bool)`**: Configures whether to strip frontmatter from the markdown content. - **`with_left_padding(self, padding: bool)`**: Configures left padding for the widget. - **`set_content(&mut self, content: &str)`**: Sets the markdown content to be displayed. - **`clear(&mut self)`**: Clears the current content of the widget. - **`is_empty(&self) -> bool`**: Checks if the widget is currently empty. - **`set_tree(&mut self, tree: Option)`**: Sets the collapsible tree data for the widget. - **`tree_mut(&mut self) -> Option<&mut CollapsibleTree>`**: Gets a mutable reference to the collapsible tree. - **`has_tree(&self) -> bool`**: Checks if the widget currently has a tree. - **`toggle_tree_node(&mut self) -> bool`**: Toggles the expansion state of the current tree node. - **`set_action_items(&mut self, items: Vec)`**: Sets the list of action items for the widget. - **`selected_action_id(&self) -> Option<&str>`**: Gets the ID of the currently selected action item. - **`scroll_up(&mut self)`**: Scrolls the content up by one line. - **`scroll_down(&mut self)`**: Scrolls the content down by one line. - **`scroll_to_top(&mut self)`**: Scrolls the content to the very top. - **`scroll_to_bottom(&mut self)`**: Scrolls the content to the very bottom. - **`page_up(&mut self, lines: usize)`**: Scrolls the content up by a specified number of lines. - **`page_down(&mut self, lines: usize)`**: Scrolls the content down by a specified number of lines. - **`total_lines(&self) -> usize`**: Gets the total number of lines in the content. - **`scroll_offset(&self) -> usize`**: Gets the current scroll offset. - **`visible_height(&self) -> usize`**: Gets the visible height of the widget in lines. - **`is_engaged(&self) -> bool`**: Checks if the widget is currently engaged (e.g., has focus). - **`engaged_cursor(&self) -> Option<(usize, usize)>`**: Gets the cursor position if the widget is engaged. - **`selected_item_id(&self) -> Option<&str>`**: Gets the ID of the currently selected item. - **`render(&mut self, f: &mut Frame, inner_area: Rect, outer_area: Rect, theme: &impl RichTextTheme)`**: Renders the widget to the given areas with the specified theme. ``` -------------------------------- ### FollowScrollState Structure Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/scroll.md Defines the `FollowScrollState` structure, intended for managing the state of auto-following content, such as in streaming output scenarios. ```rust pub struct FollowScrollState { // tracks whether the viewport is at the bottom } ``` -------------------------------- ### MarkdownRenderer Structure and Methods Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/markdown.md Defines the MarkdownRenderer struct and its core methods for parsing and rendering markdown text. The constructor takes the maximum width for text wrapping and table sizing. ```rust pub struct MarkdownRenderer { max_width: usize, } impl MarkdownRenderer { pub fn new(max_width: usize) -> Self; pub fn parse(&self, markdown: &str) -> Vec; pub fn render(&self, blocks: &[MarkdownBlock], theme: &impl RichTextTheme) -> Vec>; } ``` -------------------------------- ### Inline Formatting Parsing Function Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/markdown.md Provides a standalone function for parsing inline markdown formatting within a given text. This function can be used independently of the main MarkdownRenderer. ```rust pub fn parse_inline_formatting(text: &str, theme: &impl RichTextTheme) -> Vec>; ``` -------------------------------- ### Generation Token for Cache Invalidation Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/theme.md A simple struct to manage theme generation. Incrementing this token signals changes to the theme, triggering cache invalidation for rendered output. ```rust #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub struct Generation(pub u64); impl Generation { pub fn next(&self) -> Self { Self(self.0 + 1) } } ``` -------------------------------- ### Conventional Commit Message Format Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/contributing.md Specifies the format for commit messages, including the type and a short description. ```text type: short description type: feat, fix, refactor, test, docs, chore, ci, style ``` -------------------------------- ### Implement a Custom RichTextTheme Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/getting-started.md Define a struct that implements the RichTextTheme trait to customize colors for various elements like text, borders, and JSON components. Changing the generation value can force a cache re-render. ```rust use ratatui::style::Color; use ratatui_markdown::theme::{Generation, RichTextTheme}; struct MyTheme; impl RichTextTheme for MyTheme { fn generation(&self) -> Generation { Generation(1) } fn get_text_color(&self) -> Color { Color::White } fn get_muted_text_color(&self) -> Color { Color::Gray } fn get_primary_color(&self) -> Color { Color::Cyan } fn get_secondary_color(&self) -> Color { Color::Blue } fn get_info_color(&self) -> Color { Color::LightBlue } fn get_background_color(&self) -> Color { Color::Black } fn get_border_color(&self) -> Color { Color::DarkGray } fn get_focused_border_color(&self) -> Color { Color::White } fn get_popup_selected_background(&self) -> Color { Color::DarkGray } fn get_popup_selected_text_color(&self) -> Color { Color::White } fn get_json_key_color(&self) -> Color { Color::LightCyan } fn get_json_string_color(&self) -> Color { Color::Green } fn get_json_number_color(&self) -> Color { Color::Yellow } fn get_json_bool_color(&self) -> Color { Color::Magenta } fn get_json_null_color(&self) -> Color { Color::DarkGray } fn get_accent_yellow(&self) -> Color { Color::Yellow } } ``` -------------------------------- ### CollapsibleTree Tree Manipulation Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Methods for interacting with the tree structure, including toggling nodes, expanding/collapsing all nodes, and expanding to a specific depth. ```APIDOC ## CollapsibleTree Tree Manipulation ### `toggle` Toggles the expansion state of a node using a slash-separated path. Example: ```rust tree.toggle("dependencies"); tree.toggle("dependencies/serde"); ``` ### `handle_toggle` Convenience method for toggling a node based on a selected item's ID, typically used in a scroll context. Example: ```rust if scroll.selected_item_id().is_some() { tree.handle_toggle(selected_id); } ``` ### `expand_all` Expands all nodes in the tree. ### `collapse_all` Collapses all nodes in the tree. ### `expand_to_depth` Expands all nodes up to a specified depth. ``` -------------------------------- ### HybridScrollView Structure Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/scroll.md Defines the structure and available methods for the HybridScrollView widget, which manages scrolling, focus regions, and rendering. ```rust pub struct HybridScrollView { /* fields */ } impl HybridScrollView { pub fn new() -> Self; pub fn with_left_padding(self, padding: bool) -> Self; pub fn with_cursor_indicator(self, show: bool) -> Self; // Content management pub fn set_content(&mut self, lines: Vec>, regions: Vec); pub fn set_lines(&mut self, lines: Vec>); pub fn clear(&mut self); pub fn is_empty(&self) -> bool; // Scroll state pub fn total_lines(&self) -> usize; pub fn get_scroll_offset(&self) -> usize; pub fn get_viewport_height(&self) -> usize; pub fn set_scroll_offset(&mut self, offset: usize); // Navigation pub fn scroll_up(&mut self); pub fn scroll_down(&mut self); pub fn scroll_to_top(&mut self); pub fn scroll_to_bottom(&mut self); pub fn page_up(&mut self, lines: usize); pub fn page_down(&mut self, lines: usize); // Engagement pub fn is_engaged(&self) -> bool; pub fn engaged_cursor(&self) -> Option<(usize, usize)>; pub fn selected_item_id(&self) -> Option<&str>; pub fn engage_first(&mut self); pub fn engage_by_id(&mut self, id: &str) -> bool; // Rendering pub fn render(&mut self, f: &mut Frame, inner_area: Rect, outer_area: Rect, theme: &impl RichTextTheme); } ``` -------------------------------- ### EntryKind Enum Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Defines the possible kinds for a tree entry: Collapsed (has children, currently collapsed), Expanded (has children, currently expanded), or Leaf (no children). ```rust pub enum EntryKind { Collapsed, // has children, currently collapsed: [+] Expanded, // has children, currently expanded: [-] Leaf, // no children } ``` -------------------------------- ### FlatEntry Data Structure Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Represents a single visible entry in the flattened tree, including its depth, key, value, kind, type, path, and whether it's the last entry in its group. ```rust pub struct FlatEntry { pub depth: usize, pub key: String, pub value: String, pub kind: EntryKind, pub value_type: ValueType, pub path: String, // e.g. "dependencies/serde" pub is_last: bool, } ``` -------------------------------- ### ArrowScrollbar Rendering Function Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/scroll.md Provides the function signature for `render_arrow_scrollbar`, used to draw a custom scrollbar with Unicode arrow symbols. ```rust pub fn render_arrow_scrollbar( area: Rect, buf: &mut Buffer, top: usize, bottom: usize, theme: &impl RichTextTheme, ); ``` -------------------------------- ### ScrollableRenderResult Structure Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/scroll.md Defines the `ScrollableRenderResult` structure, used in conjunction with the `render_scrollable` function for rendering scrollable panels. ```rust pub fn render_scrollable( lines: &[Line], scroll_offset: usize, area: Rect, buf: &mut Buffer, ) -> ScrollableRenderResult; ``` -------------------------------- ### RichTextTheme Trait Definition Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/theme.md Defines the interface for custom themes, specifying methods to retrieve colors for text, accents, borders, popups, and JSON/tree values. Implement this trait to control the application's appearance. ```rust pub trait RichTextTheme { fn generation(&self) -> Generation; // General text fn get_text_color(&self) -> Color; fn get_muted_text_color(&self) -> Color; fn get_background_color(&self) -> Color; // Accent / emphasis fn get_primary_color(&self) -> Color; fn get_secondary_color(&self) -> Color; fn get_info_color(&self) -> Color; // Borders fn get_border_color(&self) -> Color; fn get_focused_border_color(&self) -> Color; // Popups / overlays fn get_popup_selected_background(&self) -> Color; fn get_popup_selected_text_color(&self) -> Color; // JSON/Tree values fn get_json_key_color(&self) -> Color; fn get_json_string_color(&self) -> Color; fn get_json_number_color(&self) -> Color; fn get_json_bool_color(&self) -> Color; fn get_json_null_color(&self) -> Color; // Misc fn get_accent_yellow(&self) -> Color; } ``` -------------------------------- ### ValueType Enum Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/tree.md Enumerates the possible data types for a tree entry's value: String, Number, Boolean, Null, Object, or Array. ```rust pub enum ValueType { String, Number, Boolean, Null, Object, Array, } ``` -------------------------------- ### ListItemRenderer Trait Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/scroll.md Defines the `ListItemRenderer` trait, which must be implemented to customize how individual items within a scrollable list are rendered. ```rust pub trait ListItemRenderer { fn render_item(&self, index: usize, is_selected: bool, width: usize) -> Line<'static>; } ``` -------------------------------- ### MarkdownBlock Enum Definition Source: https://github.com/celestia-island/ratatui-markdown/blob/master/docs/guides/en/markdown.md Defines the MarkdownBlock enum, representing the different types of markdown elements that can be parsed. Each variant holds the data associated with its corresponding markdown structure. ```rust pub enum MarkdownBlock { Heading1(String), Heading2(String), Heading3(String), Paragraph(Vec), CodeBlock(String, String), InlineCode(String), ListItem(String, u8), Blockquote(String), HorizontalRule, BlankLine, Table { headers: Vec, rows: Vec>, }, } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.