Skip to main content

ParseState

Struct ParseState 

Source
pub struct ParseState {
Show 51 fields pub buffer: Vec<u8>, pub current_line: String, pub first_line: bool, pub last_line_empty: bool, pub is_pty: bool, pub is_exec: bool, pub maybe_prompt: bool, pub prompt_regex: Option<Regex>, pub emit_flag: Option<EmitFlag>, pub scrape: Option<String>, pub scrape_ix: usize, pub terminal: Option<String>, pub width_arg: Option<usize>, pub width_full: Option<usize>, pub width_wrap: bool, pub first_indent: Option<usize>, pub has_newline: bool, pub bg: String, pub code_buffer: String, pub code_buffer_raw: String, pub code_gen: usize, pub code_language: Option<String>, pub code_first_line: bool, pub code_indent: usize, pub code_line: String, pub ordered_list_numbers: Vec<usize>, pub list_item_stack: Vec<(usize, ListType)>, pub list_indent_text: usize, pub in_list: bool, pub in_code: Option<Code>, pub inline_code: bool, pub in_bold: bool, pub in_italic: bool, pub in_table: Option<Code>, pub in_underline: bool, pub in_strikeout: bool, pub block_depth: usize, pub block_type: Option<BlockType>, pub exec_sub: Option<String>, pub exec_master: Option<i32>, pub exec_slave: Option<i32>, pub exec_kb: usize, pub exit: i32, pub where_from: Option<String>, pub links: bool, pub images: bool, pub code_spaces: bool, pub clipboard: bool, pub logging: bool, pub timeout: f64, pub savebrace: bool,
}
Expand description

Main parse state for streaming markdown processing.

This struct maintains all the state needed to incrementally parse markdown as it streams in. It tracks formatting states, list contexts, code blocks, tables, and various configuration options.

§Example

use streamdown_core::ParseState;

let mut state = ParseState::new();
state.set_width(80);

Fields§

§buffer: Vec<u8>

Raw byte buffer for incomplete UTF-8 sequences

§current_line: String

Current line being processed

§first_line: bool

Whether this is the first line of input

§last_line_empty: bool

Whether the last line was empty

§is_pty: bool

Whether input is from a PTY

§is_exec: bool

Whether in execution mode

§maybe_prompt: bool

Whether we might be at a shell prompt

§prompt_regex: Option<Regex>

Compiled regex for prompt detection

§emit_flag: Option<EmitFlag>

Current emit flag for special output handling

§scrape: Option<String>

Scrape buffer for content extraction

§scrape_ix: usize

Current index in scrape buffer

§terminal: Option<String>

Terminal reference (placeholder for terminal handle)

§width_arg: Option<usize>

User-specified width argument

§width_full: Option<usize>

Full terminal width

§width_wrap: bool

Whether to wrap text

§first_indent: Option<usize>

First line indentation level

§has_newline: bool

Whether current content has a newline

§bg: String

Current background color code

§code_buffer: String

Buffer for code block content (with highlighting)

§code_buffer_raw: String

Raw code buffer (without highlighting)

§code_gen: usize

Generation counter for code blocks

§code_language: Option<String>

Language of current code block

§code_first_line: bool

Whether on first line of code block

§code_indent: usize

Indentation level of code block

§code_line: String

Current line in code block

§ordered_list_numbers: Vec<usize>

Stack of ordered list numbers for nested lists

§list_item_stack: Vec<(usize, ListType)>

Stack of (indent, type) for nested lists

§list_indent_text: usize

Text indentation for list content

§in_list: bool

Whether currently in a list

§in_code: Option<Code>

Current code block type (None if not in code)

§inline_code: bool

Whether inline code is active

§in_bold: bool

Whether bold formatting is active

§in_italic: bool

Whether italic formatting is active

§in_table: Option<Code>

Current table state (None if not in table)

§in_underline: bool

Whether underline formatting is active

§in_strikeout: bool

Whether strikeout formatting is active

§block_depth: usize

Current block quote depth

§block_type: Option<BlockType>

Type of current block element

§exec_sub: Option<String>

Subprocess handle placeholder

§exec_master: Option<i32>

Master PTY fd placeholder

§exec_slave: Option<i32>

Slave PTY fd placeholder

§exec_kb: usize

Keyboard input counter for exec mode

§exit: i32

Exit code

§where_from: Option<String>

Debug: where input came from

§links: bool

Enable link rendering

§images: bool

Enable image rendering

§code_spaces: bool

Enable space-indented code blocks

§clipboard: bool

Enable clipboard integration

§logging: bool

Enable logging

§timeout: f64

Timeout for streaming operations (seconds)

§savebrace: bool

Save brace matching state

Implementations§

Source§

impl ParseState

Source

pub fn new() -> Self

Create a new ParseState with default values.

§Example
use streamdown_core::ParseState;
let state = ParseState::new();
assert!(state.first_line);
Source

pub fn current(&self) -> InlineState

Returns a snapshot of current inline formatting states.

This captures whether bold, italic, underline, strikeout, and inline code are currently active.

§Example
use streamdown_core::ParseState;
let mut state = ParseState::new();
state.in_bold = true;
let inline = state.current();
assert!(inline.in_bold);
Source

pub fn reset_inline(&mut self)

Reset all inline formatting states to false.

This is typically called when exiting a block that should not carry inline formatting across boundaries.

§Example
use streamdown_core::ParseState;
let mut state = ParseState::new();
state.in_bold = true;
state.in_italic = true;
state.reset_inline();
assert!(!state.in_bold);
assert!(!state.in_italic);
Source

pub fn set_width(&mut self, width: usize)

Set the terminal width.

§Arguments
  • width - The terminal width in columns
Source

pub fn full_width(&self, offset: usize) -> usize

Calculate the full available width with an optional offset.

Returns the full terminal width minus the offset. If no width is configured, returns a default of 80.

§Arguments
  • offset - Number of columns to subtract from full width
§Example
use streamdown_core::ParseState;
let mut state = ParseState::new();
state.set_width(100);
assert_eq!(state.full_width(10), 90);
Source

pub fn current_width(&self, listwidth: bool) -> usize

Calculate the current usable width for content.

This takes into account:

  • Base terminal width
  • Block quote depth (each level uses 2 columns)
  • List indentation (if listwidth is true)
§Arguments
  • listwidth - Whether to account for list indentation
§Example
use streamdown_core::ParseState;
let mut state = ParseState::new();
state.set_width(80);
state.block_depth = 2;
assert_eq!(state.current_width(false), 76); // 80 - (2 * 2)
Source

pub fn space_left(&self, listwidth: bool) -> String

Generate the left spacing/margin string for current context.

This creates the appropriate leading whitespace and block quote markers for the current nesting level.

§Arguments
  • listwidth - Whether to include list indentation
§Example
use streamdown_core::ParseState;
let mut state = ParseState::new();
state.block_depth = 1;
let margin = state.space_left(false);
assert_eq!(margin, "│ ");
Source

pub fn is_in_code(&self) -> bool

Check if currently inside any code block.

Source

pub fn is_in_table(&self) -> bool

Check if currently inside a table.

Source

pub fn has_inline_formatting(&self) -> bool

Check if any inline formatting is active.

Source

pub fn push_list(&mut self, indent: usize, list_type: ListType)

Push a new list level onto the stack.

§Arguments
  • indent - Indentation level of the list
  • list_type - Type of list (Bullet or Ordered)
Source

pub fn pop_list(&mut self) -> Option<(usize, ListType)>

Pop the current list level from the stack.

Returns the popped (indent, type) tuple if the stack was non-empty.

Source

pub fn list_depth(&self) -> usize

Get the current list depth (nesting level).

Source

pub fn next_list_number(&mut self) -> Option<usize>

Get and increment the current ordered list number.

Returns the current number before incrementing.

Source

pub fn enter_code_block(&mut self, code_type: Code, language: Option<String>)

Enter a code block.

§Arguments
  • code_type - The type of code block (Backtick or Spaces)
  • language - Optional language identifier
Source

pub fn exit_code_block(&mut self)

Exit the current code block.

Source

pub fn enter_block(&mut self, block_type: BlockType)

Enter a block quote.

§Arguments
  • block_type - The type of block (Quote or Think)
Source

pub fn exit_block(&mut self)

Exit one level of block quote.

Trait Implementations§

Source§

impl Clone for ParseState

Source§

fn clone(&self) -> ParseState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParseState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ParseState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.