use std::io::Write;
use anyhow::Result;
use pulldown_cmark::Event;
use pulldown_cmark::Parser;
use pulldown_cmark::Tag;
pub(crate) fn write_raw_to<W>(parser: &mut Parser<'_>, w: &mut W) -> Result<()>
where
W: Write,
{
for event in parser.into_iter() {
match event {
Event::Start(tag) => {
writeln!(w, "Start({:?})", tag)?;
match tag {
Tag::Paragraph => {
writeln!(w, "Event::Start(Tag::Paragraph)")?;
}
Tag::Heading {
level,
id,
classes,
attrs,
} => {
writeln!(
w,
"Event::Start(Tag::Heading{{ level: {} fragment identifier: {:?} classes: {:?} attributes: {:?} }})",
level, id, classes, attrs
)?;
}
Tag::BlockQuote => {
writeln!(w, "Event::Start(Tag::BlockQuote)")?;
}
Tag::CodeBlock(code_block_kind) => {
writeln!(
w,
"Event::Start(Tag::CodeBlock(code_block_kind: {:?} ))",
code_block_kind
)?;
}
Tag::HtmlBlock => {
writeln!(w, "Event::Start(Tag::HtmlBlock)")?;
}
Tag::List(ordered_list_first_item_number) => {
writeln!(
w,
"Event::Start(Tag::List( ordered_list_first_item_number: {:?} ))",
ordered_list_first_item_number
)?;
}
Tag::Item => {
writeln!(w, "Event::Start(Tag::Item) (this is a list item)")?;
}
Tag::FootnoteDefinition(label) => {
writeln!(
w,
"Event::Start(Tag::FootnoteDefinition( label: {} ))",
label
)?;
}
Tag::Table(column_text_alignment_list) => {
writeln!(
w,
"Event::Start(Tag::Table( column_text_alignment_list: {:?} ))",
column_text_alignment_list
)?;
}
Tag::TableHead => {
writeln!(w, "Event::Start(Tag::TableHead) (contains TableRow tags)")?;
}
Tag::TableRow => {
writeln!(w, "Event::Start(Tag::TableRow) (contains TableCell tags)")?;
}
Tag::TableCell => {
writeln!(w, "Event::Start(Tag::TableCell) (contains inline tags)")?;
}
Tag::Emphasis => {
writeln!(w, "Event::Start(Tag::Emphasis) (this is a span tag)")?;
}
Tag::Strong => {
writeln!(w, "Event::Start(Tag::Strong) (this is a span tag)")?;
}
Tag::Strikethrough => {
writeln!(w, "Event::Start(Tag::Strikethrough) (this is a span tag)")?;
}
Tag::Link {
link_type,
dest_url,
title,
id,
} => {
writeln!(
w,
"Event::Start(Tag::Link{{ link_type: {:?} url: {} title: {} id: {} }})",
link_type, dest_url, title, id
)?;
}
Tag::Image {
link_type,
dest_url,
title,
id,
} => {
writeln!(
w,
"Event::Start(Tag::Image( link_type: {:?} url: {} title: {} id: {} ))",
link_type, dest_url, title, id
)?;
}
Tag::MetadataBlock(kind) => {
writeln!(w, "Event::Start(Tag::MetadataBlock({:?}))", kind)?;
}
}
}
Event::End(tag) => {
writeln!(w, "Event::End({:?})", tag)?;
}
Event::Text(s) => {
writeln!(w, "Event::Text({:?})", s)?;
}
Event::Code(s) => {
writeln!(w, "Event::Code({:?})", s)?;
}
Event::Html(s) => {
writeln!(w, "Event::Html({:?})", s)?;
}
Event::InlineHtml(s) => {
writeln!(w, "Event::InlineHtml({:?})", s)?;
}
Event::FootnoteReference(s) => {
writeln!(w, "Event::FootnoteReference({:?})", s)?;
}
Event::SoftBreak => {
writeln!(w, "Event::SoftBreak")?;
}
Event::HardBreak => {
writeln!(w, "Event::HardBreak")?;
}
Event::Rule => {
writeln!(w, "Event::Rule")?;
}
Event::TaskListMarker(b) => {
writeln!(w, "Event::TaskListMarker({:?})", b)?;
}
};
}
Ok(())
}
#[cfg(test)]
mod test {
}