Expand description
Markdown to DocSpec event stream reader.
This crate provides a MarkdownReader that implements EventSource to convert
Markdown documents into the DocSpec event stream format. It uses pulldown-cmark
to parse CommonMark-compliant Markdown and emits typed events representing document
structure.
§Quick Start
use docspec_markdown_reader::{MarkdownReader, EventSource};
let markdown = "# Hello\n\nWorld";
let mut reader = MarkdownReader::new(markdown);
while let Some(event) = reader.next_event()? {
println!("{event:?}");
}§Supported Elements
- Headings (h1–h6) →
StartHeading/EndHeading - Paragraphs →
StartParagraph/EndParagraph - Block quotes →
StartBlockQuote/EndBlockQuote - Code blocks →
StartPreformatted/EndPreformatted - Bold text →
Text { style: TextStyle { bold: true, .. }, .. } - Italic text →
Text { style: TextStyle { italic: true, .. }, .. } - Inline code →
Text { style: TextStyle { code: true, .. }, .. } - Strikethrough →
Text { style: TextStyle { strikethrough: true, .. }, .. } - Images →
Image { source: Uri, alt, title, decorative } - Hard line breaks →
LineBreak - Soft line breaks →
SoftBreak - Thematic breaks →
ThematicBreak - Tables →
StartTable/EndTable,StartTableRow/EndTableRow,StartTableHeader/EndTableHeader,StartTableCell/EndTableCell(GFM column alignment syntax is parsed, but alignment data is discarded) - Bullet lists →
StartUnorderedListItem/EndUnorderedListItem - Numbered lists →
StartOrderedListItem/EndOrderedListItem(start: Option<u64>isSome(n)on the first item of each list,Noneon subsequent items; child items may nest inside their parent’sStart*/End*pair withlevelindicating indent depth; task list markers (- [ ]/- [x]) are parsed as literal text) - Links →
StartLink { href, title }/EndLink(inline, reference, collapsed, shortcut, autolink, and email autolink variants — all resolved to inline form by pulldown-cmark; image-inside-link closes the link before emitting the image as a sibling block: content preceding the image stays inside the link, content following the image is outside the link, and the link is empty only when the image is the sole link label, e.g.[](url))
§Unsupported Elements
The following elements are not emitted as structured events. Text content is recursively extracted where applicable; structure is silently dropped:
- Definition lists and footnotes
- HTML blocks and inline HTML
- Math blocks and inline math
- Subscript and superscript formatting
Structs§
- Markdown
Reader - A streaming Markdown reader that implements
EventSource.
Traits§
- Event
Source - Produces a stream of
crate::Events from a document source.