pub struct HighlightContext { /* private fields */ }Expand description
Context passed to SyntaxHighlighter::highlight_block.
Provides methods to set highlight formatting and manage per-block state.
Implementations§
Source§impl HighlightContext
impl HighlightContext
Sourcepub fn new(
block_id: usize,
previous_state: i64,
user_data: Option<Box<dyn Any + Send + Sync>>,
) -> Self
pub fn new( block_id: usize, previous_state: i64, user_data: Option<Box<dyn Any + Send + Sync>>, ) -> Self
Create a new context for highlighting a block.
Sourcepub fn set_format(
&mut self,
start: usize,
length: usize,
format: HighlightFormat,
)
pub fn set_format( &mut self, start: usize, length: usize, format: HighlightFormat, )
Apply a highlight format to a character range within the current block.
Zero-length spans are silently ignored.
Sourcepub fn previous_block_state(&self) -> i64
pub fn previous_block_state(&self) -> i64
Get the block state of the previous block (−1 if no state was set).
Sourcepub fn set_current_block_state(&mut self, state: i64)
pub fn set_current_block_state(&mut self, state: i64)
Set the block state for the current block.
If the new state differs from the previously stored value, the next block will be re-highlighted automatically (cascade).
Sourcepub fn current_block_state(&self) -> i64
pub fn current_block_state(&self) -> i64
Get the current block state (defaults to −1).
Sourcepub fn set_user_data(&mut self, data: Box<dyn Any + Send + Sync>)
pub fn set_user_data(&mut self, data: Box<dyn Any + Send + Sync>)
Set per-block user data (replaces any existing data).
Sourcepub fn user_data(&self) -> Option<&(dyn Any + Send + Sync)>
pub fn user_data(&self) -> Option<&(dyn Any + Send + Sync)>
Get a reference to the per-block user data.
Sourcepub fn user_data_mut(&mut self) -> Option<&mut (dyn Any + Send + Sync)>
pub fn user_data_mut(&mut self) -> Option<&mut (dyn Any + Send + Sync)>
Get a mutable reference to the per-block user data.
Sourcepub fn into_parts(
self,
) -> (Vec<HighlightSpan>, i64, Option<Box<dyn Any + Send + Sync>>)
pub fn into_parts( self, ) -> (Vec<HighlightSpan>, i64, Option<Box<dyn Any + Send + Sync>>)
Consume the context and return the accumulated spans, final state, and user data.