Expand description
pulldown-html-ext
A configurable Markdown to HTML renderer built on top of pulldown-cmark.
§Documentation
§Quick Start
use pulldown_html_ext::{HtmlConfig, push_html};
use pulldown_cmark::Parser;
let config = HtmlConfig::default();
let markdown = "# Hello\nThis is *markdown*";
let parser = Parser::new(markdown);
let mut output = String::new();
let html = push_html(&mut output, parser, &config).unwrap();
Custom rendering with a custom writer:
use pulldown_html_ext::{HtmlConfig, HtmlWriter, HtmlState, HtmlRenderer};
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 = HtmlRenderer::new(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§
- utils
- Utility functions for HTML rendering and string manipulation
Structs§
- Attribute
Mappings - Custom attribute mappings for HTML elements
- Code
Block Options - Configuration options for code blocks
- Default
Html Writer - An HTML writer implementation. This type implements methods for writing HTML elements. Default HTML writer implementation that can work with any StrWrite-compatible writer This should be the approximate amount of code any custom implementation needs to provide
- Element
Options - Configuration options for different Markdown elements
- Heading
Options - Configuration options for headings
- Html
Config - Main configuration struct for the HTML renderer
- Html
Options - Configuration options for HTML output
- Html
Renderer - Html
State - Maintains the state of the HTML rendering process
- Html
Writer Base - Base type for HTML writers that handles common functionality
- Link
Options - Configuration options for links
- Syntect
Config - Complete syntax highlighting configuration including non-clonable parts
- Syntect
Config Style - Configuration options for syntax highlighting that can be cloned
- Syntect
Writer - An HTML writer implementation. This type implements methods for writing HTML elements. Writer that adds syntax highlighting to code blocks
Enums§
- Html
Error - Custom error type for HTML rendering operations
Traits§
- Html
Writer - Trait for handling Markdown tag rendering to HTML
Functions§
- push_
html - Renders markdown events to HTML and appends to the provided string
- push_
html_ with_ highlighting - Convenience function to render Markdown with syntax highlighting
- write_
html_ fmt - Renders markdown events to HTML using a fmt::Write implementation
- write_
html_ io - Renders markdown events to HTML using an io::Write implementation