pub struct CommonMarkWriter { /* private fields */ }Expand description
CommonMark writer
This struct is responsible for serializing AST nodes to CommonMark-compliant text.
Implementations§
Source§impl CommonMarkWriter
impl CommonMarkWriter
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new CommonMark writer with default options
§Example
use cmark_writer::writer::CommonMarkWriter;
use cmark_writer::ast::Node;
let mut writer = CommonMarkWriter::new();
writer.write(&Node::Text("Hello".to_string())).unwrap();
assert_eq!(writer.into_string(), "Hello");Sourcepub fn with_options(options: WriterOptions) -> Self
pub fn with_options(options: WriterOptions) -> Self
Create a new CommonMark writer with specified options
§Parameters
options- Custom CommonMark formatting options
§Example
use cmark_writer::writer::{CommonMarkWriter, WriterOptions};
let options = WriterOptions {
strict: true,
hard_break_spaces: false, // Use backslash for line breaks
indent_spaces: 2, // Use 2 spaces for indentation
};
let writer = CommonMarkWriter::with_options(options);Sourcepub fn write(&mut self, node: &Node) -> Result
pub fn write(&mut self, node: &Node) -> Result
Write an AST node as CommonMark format
§Parameters
node- The AST node to write
§Returns
If writing succeeds, returns Ok(()), otherwise returns Err(fmt::Error)
§Example
use cmark_writer::writer::CommonMarkWriter;
use cmark_writer::ast::Node;
let mut writer = CommonMarkWriter::new();
writer.write(&Node::Text("Hello".to_string())).unwrap();Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Get the generated CommonMark format text
Consumes the writer and returns the generated string
§Example
use cmark_writer::writer::CommonMarkWriter;
use cmark_writer::ast::Node;
let mut writer = CommonMarkWriter::new();
writer.write(&Node::Text("Hello".to_string())).unwrap();
let result = writer.into_string();
assert_eq!(result, "Hello");Trait Implementations§
Source§impl Debug for CommonMarkWriter
impl Debug for CommonMarkWriter
Auto Trait Implementations§
impl Freeze for CommonMarkWriter
impl RefUnwindSafe for CommonMarkWriter
impl Send for CommonMarkWriter
impl Sync for CommonMarkWriter
impl Unpin for CommonMarkWriter
impl UnwindSafe for CommonMarkWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more