pub struct MarkdownCommands;Expand description
Markdown-aware editing commands that operate on a kode-core Editor.
Each command reads the current editor state, then applies text operations via the Editor API. All edits are pure text transforms.
Note: inline mark toggle commands read directly from the editor buffer, not from the tree, so they always operate on current text.
Implementations§
Source§impl MarkdownCommands
impl MarkdownCommands
Sourcepub fn toggle_bold(editor: &mut Editor)
pub fn toggle_bold(editor: &mut Editor)
Toggle bold (**) around the current selection.
If selection is already bold, removes the markers.
If no selection, inserts **** and places cursor between them.
Sourcepub fn toggle_italic(editor: &mut Editor)
pub fn toggle_italic(editor: &mut Editor)
Toggle italic (*) around the current selection.
Sourcepub fn toggle_inline_code(editor: &mut Editor)
pub fn toggle_inline_code(editor: &mut Editor)
Toggle inline code (`) around the current selection.
Sourcepub fn toggle_strikethrough(editor: &mut Editor)
pub fn toggle_strikethrough(editor: &mut Editor)
Toggle strikethrough (~~) around the current selection.
Sourcepub fn set_heading(editor: &mut Editor, level: u8)
pub fn set_heading(editor: &mut Editor, level: u8)
Set the heading level for the current line. Level 0 removes the heading prefix. Levels 1-6 set the corresponding heading.
Sourcepub fn toggle_blockquote(editor: &mut Editor)
pub fn toggle_blockquote(editor: &mut Editor)
Toggle a block quote on the current line or selection.
If already quoted, removes the > prefix. Otherwise adds it.
Uses atomic transaction for multi-line operations.
Sourcepub fn toggle_bullet_list(editor: &mut Editor)
pub fn toggle_bullet_list(editor: &mut Editor)
Toggle a bullet list prefix on the current line or selection.
If already a list item, removes - . Otherwise adds - .
Lines already prefixed are skipped when adding (no double-prefix).
Sourcepub fn toggle_ordered_list(editor: &mut Editor)
pub fn toggle_ordered_list(editor: &mut Editor)
Toggle an ordered list prefix on the current line or selection.
Sourcepub fn insert_link(editor: &mut Editor, url: &str)
pub fn insert_link(editor: &mut Editor, url: &str)
Insert a link at the cursor: [text](url)
If there’s a selection, it becomes the link text.
Sourcepub fn insert_code_block(editor: &mut Editor, language: &str)
pub fn insert_code_block(editor: &mut Editor, language: &str)
Insert a fenced code block at the cursor.
Sourcepub fn insert_paragraph_break(editor: &mut Editor, newline: &str)
pub fn insert_paragraph_break(editor: &mut Editor, newline: &str)
Insert a paragraph break (Enter key), properly closing and reopening
any active inline markers (**, *, `, ~~) so formatting
is not broken across the line boundary.
newline controls what is inserted: "\n\n" for a normal paragraph
break, "\n" for a soft break (Shift+Enter).
Sourcepub fn insert_horizontal_rule(editor: &mut Editor)
pub fn insert_horizontal_rule(editor: &mut Editor)
Insert a horizontal rule.
Sourcepub fn formatting_at_cursor(editor: &Editor) -> FormattingState
pub fn formatting_at_cursor(editor: &Editor) -> FormattingState
Determine which formatting is active at the current cursor position.
Inline formatting (bold, italic, code, strikethrough) is detected by
scanning text before the cursor for open markers via active_inline_markers.
Block formatting (headings, lists, blockquotes) is detected by checking
the line prefix.
Sourcepub fn active_inline_markers(text: &str) -> Vec<&'static str>
pub fn active_inline_markers(text: &str) -> Vec<&'static str>
Scan text from line start to cursor and return a list of inline markers that are currently “open” (i.e. have an odd number of occurrences).
Returns markers in the order they were opened, which matters for
correct nesting (e.g. ** before * in ***bold-italic***).
Handles the tricky * vs ** disambiguation: ** is consumed first
(greedy), then remaining lone * is italic.