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: StringCurrent line being processed
first_line: boolWhether this is the first line of input
last_line_empty: boolWhether the last line was empty
is_pty: boolWhether input is from a PTY
is_exec: boolWhether in execution mode
maybe_prompt: boolWhether 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: usizeCurrent 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: boolWhether to wrap text
first_indent: Option<usize>First line indentation level
has_newline: boolWhether current content has a newline
bg: StringCurrent background color code
code_buffer: StringBuffer for code block content (with highlighting)
code_buffer_raw: StringRaw code buffer (without highlighting)
code_gen: usizeGeneration counter for code blocks
code_language: Option<String>Language of current code block
code_first_line: boolWhether on first line of code block
code_indent: usizeIndentation level of code block
code_line: StringCurrent 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: usizeText indentation for list content
in_list: boolWhether currently in a list
in_code: Option<Code>Current code block type (None if not in code)
inline_code: boolWhether inline code is active
in_bold: boolWhether bold formatting is active
in_italic: boolWhether italic formatting is active
in_table: Option<Code>Current table state (None if not in table)
in_underline: boolWhether underline formatting is active
in_strikeout: boolWhether strikeout formatting is active
block_depth: usizeCurrent 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: usizeKeyboard input counter for exec mode
exit: i32Exit code
where_from: Option<String>Debug: where input came from
links: boolEnable link rendering
images: boolEnable image rendering
code_spaces: boolEnable space-indented code blocks
clipboard: boolEnable clipboard integration
logging: boolEnable logging
timeout: f64Timeout for streaming operations (seconds)
savebrace: boolSave brace matching state
Implementations§
Source§impl ParseState
impl ParseState
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ParseState with default values.
§Example
use streamdown_core::ParseState;
let state = ParseState::new();
assert!(state.first_line);Sourcepub fn current(&self) -> InlineState
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);Sourcepub fn reset_inline(&mut self)
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);Sourcepub fn full_width(&self, offset: usize) -> usize
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);Sourcepub fn current_width(&self, listwidth: bool) -> usize
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
listwidthis 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)Sourcepub fn space_left(&self, listwidth: bool) -> String
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, "│ ");Sourcepub fn is_in_code(&self) -> bool
pub fn is_in_code(&self) -> bool
Check if currently inside any code block.
Sourcepub fn is_in_table(&self) -> bool
pub fn is_in_table(&self) -> bool
Check if currently inside a table.
Sourcepub fn has_inline_formatting(&self) -> bool
pub fn has_inline_formatting(&self) -> bool
Check if any inline formatting is active.
Sourcepub fn push_list(&mut self, indent: usize, list_type: ListType)
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 listlist_type- Type of list (Bullet or Ordered)
Sourcepub fn pop_list(&mut self) -> Option<(usize, ListType)>
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.
Sourcepub fn list_depth(&self) -> usize
pub fn list_depth(&self) -> usize
Get the current list depth (nesting level).
Sourcepub fn next_list_number(&mut self) -> Option<usize>
pub fn next_list_number(&mut self) -> Option<usize>
Get and increment the current ordered list number.
Returns the current number before incrementing.
Sourcepub fn enter_code_block(&mut self, code_type: Code, language: Option<String>)
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
Sourcepub fn exit_code_block(&mut self)
pub fn exit_code_block(&mut self)
Exit the current code block.
Sourcepub fn enter_block(&mut self, block_type: BlockType)
pub fn enter_block(&mut self, block_type: BlockType)
Sourcepub fn exit_block(&mut self)
pub fn exit_block(&mut self)
Exit one level of block quote.
Trait Implementations§
Source§impl Clone for ParseState
impl Clone for ParseState
Source§fn clone(&self) -> ParseState
fn clone(&self) -> ParseState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more