Skip to main content

HighlightContext

Struct HighlightContext 

Source
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

Source

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.

Source

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.

Source

pub fn previous_block_state(&self) -> i64

Get the block state of the previous block (−1 if no state was set).

Source

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

Source

pub fn current_block_state(&self) -> i64

Get the current block state (defaults to −1).

Source

pub fn block_id(&self) -> usize

Get the block ID.

Source

pub fn set_user_data(&mut self, data: Box<dyn Any + Send + Sync>)

Set per-block user data (replaces any existing data).

Source

pub fn user_data(&self) -> Option<&(dyn Any + Send + Sync)>

Get a reference to the per-block user data.

Source

pub fn user_data_mut(&mut self) -> Option<&mut (dyn Any + Send + Sync)>

Get a mutable reference to the per-block user data.

Source

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.

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.