pulldown-html-ext
A configurable Markdown to HTML renderer that extends pulldown-cmark. This library provides a flexible HTML rendering system with extensive configuration options, custom styling support, and attribute handling capabilities.
Features
- Configurable HTML rendering with extensive options
- Custom attribute mapping for HTML elements
- Support for heading IDs and custom classes
- Customizable code block rendering
- External link handling with
nofollow
andtarget="_blank"
options - Table support with alignment controls
- Footnote rendering
- Task list support
- XHTML-style output option
- Pretty printing support
- Syntect-based syntax highlighting for code blocks
Installation
Add this to your Cargo.toml
:
[]
= "0.1.0"
Quick Start
Here's a simple example of converting Markdown to HTML using default settings:
use ;
use Parser;
let config = default;
let markdown = "# Hello\nThis is *markdown*";
let mut output = String new;
let parser = new;
let html = push_html;
Configuration
The library provides extensive configuration options through the HtmlConfig
struct:
let mut config = default;
// Configure HTML options
config.html.escape_html = true;
config.html.break_on_newline = true;
config.html.xhtml_style = false;
config.html.pretty_print = true;
// Configure heading options
config.elements.headings.add_ids = true;
config.elements.headings.id_prefix = "heading-".to_string;
// Configure link options
config.elements.links.nofollow_external = true;
config.elements.links.open_external_blank = true;
// Configure code block options
config.elements.code_blocks.default_language = Some;
config.elements.code_blocks.line_numbers = false;
// Configure syntax highlighting ( If feature is enabled )
config.syntect = Some;
Custom Attribute Mapping
You can add custom attributes to HTML elements:
use HashMap;
let mut config = default;
let mut attrs = new;
attrs.insert;
config.attributes.element_attributes.insert;
Custom Writers
Create custom HTML writers by implementing the HtmlWriter
trait. This allows you to customize how specific Markdown elements are rendered to HTML:
use ;
use ;
use ;
// Usage example:
Syntect-based Syntax Highlighting
The library provides an optional feature to enable syntax highlighting for code blocks using the Syntect library. To use this, you can enable the syntect
feature in your Cargo.toml
:
[]
= { = "0.1.0", = ["syntect"] }
Then, you can configure the syntax highlighting options in your HtmlConfig
:
let mut config = default;
config.syntect = Some;
This will add syntax highlighting to your code blocks using the specified theme and class style.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.