Expand description
A configurable Markdown to HTML renderer built on top of pulldown-cmark.
This crate provides a flexible HTML renderer with support for custom styling, attributes, and rendering options. It extends pulldown-cmark’s capabilities while maintaining a clean, safe API.
§Examples
Basic usage with default options:
use pulldown_html_ext::{HtmlConfig, push_html};
let config = HtmlConfig::default();
let markdown = "# Hello\nThis is *markdown*";
let html = push_html(markdown, &config).unwrap();
assert!(html.contains("<h1"));
Custom rendering with a custom writer:
use pulldown_html_ext::{HtmlConfig, HtmlWriter, HtmlState, create_html_renderer};
use pulldown_cmark_escape::{StrWrite, FmtWriter};
struct CustomWriter<W: StrWrite> {
writer: W,
config: HtmlConfig,
state: HtmlState,
}
impl<W: StrWrite> CustomWriter<W> {
fn new(writer: W, config: HtmlConfig) -> Self {
Self {
writer,
config,
state: HtmlState::new(),
}
}
}
impl<W: StrWrite> HtmlWriter<W> for CustomWriter<W> {
fn get_writer(&mut self) -> &mut W {
&mut self.writer
}
fn get_config(&self) -> &HtmlConfig {
&self.config
}
fn get_state(&mut self) -> &mut HtmlState {
&mut self.state
}
}
let mut output = String::new();
let writer = CustomWriter::new(
FmtWriter(&mut output),
HtmlConfig::default()
);
let mut renderer = create_html_renderer(writer);
// Use the renderer with a parser
use pulldown_cmark::Parser;
let markdown = "# Hello\nThis is *markdown*";
let parser = Parser::new(markdown);
renderer.run(parser);
assert!(output.contains("<h1"));
Modules§
- Utility functions for HTML rendering and string manipulation
Structs§
- Custom attribute mappings for HTML elements
- Configuration options for code blocks
- Default HTML writer implementation that can work with any StrWrite-compatible writer
- Configuration options for different Markdown elements
- Configuration options for headings
- Main configuration struct for the HTML renderer
- Configuration options for HTML output
- Maintains the state of the HTML rendering process
- Configuration options for links
- Complete syntax highlighting configuration including non-clonable parts
- Configuration options for syntax highlighting that can be cloned
- Writer that adds syntax highlighting to code blocks
Enums§
- Custom error type for HTML rendering operations
Traits§
- Trait for handling Markdown tag rendering to HTML
Functions§
- Convenience function to render Markdown with syntax highlighting