Crate pulldown_html_ext

Source
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§

AttributeMappings
Custom attribute mappings for HTML elements
CodeBlockOptions
Configuration options for code blocks
DefaultHtmlWriter
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
ElementOptions
Configuration options for different Markdown elements
HeadingOptions
Configuration options for headings
HtmlConfig
Main configuration struct for the HTML renderer
HtmlOptions
Configuration options for HTML output
HtmlRenderer
HtmlState
Maintains the state of the HTML rendering process
HtmlWriterBase
Base type for HTML writers that handles common functionality
LinkOptions
Configuration options for links
SyntectConfig
Complete syntax highlighting configuration including non-clonable parts
SyntectConfigStyle
Configuration options for syntax highlighting that can be cloned
SyntectWriter
An HTML writer implementation. This type implements methods for writing HTML elements. Writer that adds syntax highlighting to code blocks

Enums§

HtmlError
Custom error type for HTML rendering operations

Traits§

HtmlWriter
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

Attribute Macros§

html_writer