cmark_writer/ast/
custom.rs

1//! Custom node definitions for the CommonMark AST.
2
3use crate::error::WriteResult;
4use std::any::Any;
5
6/// Trait for implementing custom node behavior
7pub trait CustomNode: std::fmt::Debug + Send + Sync {
8    /// Write the custom node content to the provided writer
9    fn write(&self, writer: &mut dyn CustomNodeWriter) -> WriteResult<()>;
10
11    /// Clone the custom node
12    fn clone_box(&self) -> Box<dyn CustomNode>;
13
14    /// Check if two custom nodes are equal
15    fn eq_box(&self, other: &dyn CustomNode) -> bool;
16
17    /// Whether the custom node is a block element
18    fn is_block(&self) -> bool;
19
20    /// Convert to Any for type casting
21    fn as_any(&self) -> &dyn Any;
22}
23
24/// Trait for custom node writer implementation
25pub trait CustomNodeWriter {
26    /// Write a string to the output
27    fn write_str(&mut self, s: &str) -> std::fmt::Result;
28
29    /// Write a character to the output
30    fn write_char(&mut self, c: char) -> std::fmt::Result;
31}
32
33// Implement Clone for Box<dyn CustomNode>
34impl Clone for Box<dyn CustomNode> {
35    fn clone(&self) -> Self {
36        self.clone_box()
37    }
38}
39
40// Implement PartialEq for Box<dyn CustomNode>
41impl PartialEq for Box<dyn CustomNode> {
42    fn eq(&self, other: &Self) -> bool {
43        self.eq_box(&**other)
44    }
45}