Skip to main content

MarkdownCommands

Struct MarkdownCommands 

Source
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

Source

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.

Source

pub fn toggle_italic(editor: &mut Editor)

Toggle italic (*) around the current selection.

Source

pub fn toggle_inline_code(editor: &mut Editor)

Toggle inline code (`) around the current selection.

Source

pub fn toggle_strikethrough(editor: &mut Editor)

Toggle strikethrough (~~) around the current selection.

Source

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.

Source

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.

Source

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).

Source

pub fn toggle_ordered_list(editor: &mut Editor)

Toggle an ordered list prefix on the current line or selection.

Insert a link at the cursor: [text](url) If there’s a selection, it becomes the link text.

Source

pub fn insert_code_block(editor: &mut Editor, language: &str)

Insert a fenced code block at the cursor.

Source

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).

Source

pub fn insert_horizontal_rule(editor: &mut Editor)

Insert a horizontal rule.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.