CommonMarkWriter

Struct CommonMarkWriter 

Source
pub struct CommonMarkWriter {
    pub options: WriterOptions,
    pub buffer: EcoString,
    /* private fields */
}
Expand description

CommonMark writer responsible for serializing AST nodes to CommonMark text.

Fields§

§options: WriterOptions

Writer options.

§buffer: EcoString

Buffer for storing the output text.

Implementations§

Source§

impl CommonMarkWriter

Source

pub fn new() -> Self

Create a new CommonMark writer with default options.

Source

pub fn with_options(options: WriterOptions) -> Self

Create a new CommonMark writer with specified options.

Source

pub fn with_diagnostic_sink( self, sink: Box<dyn DiagnosticSink + 'static>, ) -> Self

Replace the diagnostic sink used to capture non-fatal issues.

Source

pub fn set_diagnostic_sink(&mut self, sink: Box<dyn DiagnosticSink + 'static>)

Swap the diagnostic sink on an existing writer.

Source

pub fn diagnostic_sink(&mut self) -> &mut dyn DiagnosticSink

Get a mutable handle to the diagnostic sink.

Source

pub fn write(&mut self, node: &Node) -> WriteResult<()>

Write an AST node as CommonMark format.

Source

pub fn into_string(self) -> EcoString

Get the generated CommonMark format text.

Source

pub fn write_str(&mut self, s: &str) -> WriteResult<()>

Write a string to the output buffer.

Source

pub fn write_char(&mut self, c: char) -> WriteResult<()>

Write a character to the output buffer.

Trait Implementations§

Source§

impl Debug for CommonMarkWriter

Source§

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

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

impl Default for CommonMarkWriter

Source§

fn default() -> Self

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

impl NodeHandler for CommonMarkWriter

Source§

type Error = WriteError

Error type produced during traversal.
Source§

fn document(&mut self, children: &[Node]) -> WriteResult<()>

Source§

fn paragraph(&mut self, content: &[Node]) -> WriteResult<()>

Source§

fn text(&mut self, text: &EcoString) -> WriteResult<()>

Source§

fn emphasis(&mut self, content: &[Node]) -> WriteResult<()>

Source§

fn strong(&mut self, content: &[Node]) -> WriteResult<()>

Source§

fn thematic_break(&mut self) -> WriteResult<()>

Source§

fn heading( &mut self, level: u8, content: &[Node], heading_type: &HeadingType, ) -> WriteResult<()>

Source§

fn inline_code(&mut self, code: &EcoString) -> WriteResult<()>

Source§

fn code_block( &mut self, language: &Option<EcoString>, content: &EcoString, block_type: &CodeBlockType, ) -> WriteResult<()>

Source§

fn html_block(&mut self, content: &EcoString) -> WriteResult<()>

Source§

fn html_element(&mut self, element: &HtmlElement) -> WriteResult<()>

Source§

fn block_quote(&mut self, content: &[Node]) -> WriteResult<()>

Source§

fn unordered_list(&mut self, items: &[ListItem]) -> WriteResult<()>

Source§

fn ordered_list(&mut self, start: u32, items: &[ListItem]) -> WriteResult<()>

Source§

fn table(&mut self, headers: &[Node], rows: &[Vec<Node>]) -> WriteResult<()>

Source§

fn image( &mut self, url: &EcoString, title: &Option<EcoString>, alt: &[Node], ) -> WriteResult<()>

Source§

fn soft_break(&mut self) -> WriteResult<()>

Source§

fn hard_break(&mut self) -> WriteResult<()>

Source§

fn custom(&mut self, node: &dyn CustomNode) -> WriteResult<()>

Source§

fn unsupported(&mut self, node: &Node) -> WriteResult<()>

Source§

fn visit_node(&mut self, node: &Node) -> Result<(), Self::Error>

Dispatch a single node. Most implementers will not override this and will instead implement the per-variant methods below.
Source§

fn visit_nodes(&mut self, nodes: &[Node]) -> Result<(), Self::Error>

Visit a sequence of nodes.

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.