HTML Generator (html-generator)
A high-performance Rust library that transforms Markdown into semantically rich, accessible HTML with WCAG 2.1 compliance.
• Website • Documentation • Report Bug • Request Feature • Contributing Guidelines
Quick Links
- HTML Generator (html-generator)
Overview
HTML Generator is a high-performance Rust library for transforming Markdown into semantically rich, accessible HTML.
Key Features
Markdown Conversion
- Core Processing:
- Standard Markdown to HTML transformation
- Configurable parsing with
ComrakOptions
- Front matter extraction support
- Basic syntax highlighting via
syntect
- Inline HTML preservation
Accessibility and Semantic Markup
- ARIA and Accessibility Features:
- Automated ARIA attribute generation for:
- Buttons
- Form elements
- Navigation structures
- Interactive components
- WCAG 2.1 validation checks
- Semantic HTML structure preservation
- Automatic role inference for HTML elements
- Automated ARIA attribute generation for:
Performance Optimizations
- Efficient Processing:
- O(n) time complexity parsing
- Constant memory overhead for small documents
- Synchronous and asynchronous HTML generation methods
- Minimal runtime overhead
- Optional HTML minification
Advanced Configuration
- Flexible Transformation:
- Language-specific rendering
- Configurable syntax highlighting
- Custom block processing
- Emoji handling (limited)
- SEO metadata generation
Installation
Add to your Cargo.toml
:
[]
= "0.0.3"
Basic Usage
use ;
use Error;
Advanced Usage Configuration
use HtmlConfig;
use HtmlError;
Processing Methods
Synchronous Processing
use ;
use Error;
Asynchronous Processing
# use async_generate_html;
# use Error;
#
# // We hide the async main to avoid doc-test errors about `.await`.
# // The code inside demonstrates how you'd normally use `async_generate_html`.
# async
Error Handling
use ;
use HtmlError;
Examples
HTML Generator provides many advanced capabilities for accessibility, ARIA attributes, and custom Markdown styling. Below is a summary of what you can explore. For more detailed code, see the src/examples/
directory in this repository.
ARIA Elements & Accessibility
Add ARIA attributes to common HTML elements (buttons, forms, tables, and more) to ensure accessibility compliance. The library automatically infers roles and labels for screen readers.
Example Snippet (from aria_elements_example.rs
):
use add_aria_attributes;
use HtmlError;
Run the full ARIA demo:
This will print out multiple examples showcasing enhancements for buttons, forms, navigation elements, tables, live regions, and nested components.
Custom Markdown Styling
Demonstrate transforming extended Markdown features such as:
- Custom blocks (e.g.,
:::note
,:::warning
) - Inline
.class="..."
directives for images or elements - Syntax highlighting for fenced code blocks
- Blockquotes with optional citation
…and much more.
Example Snippet (from style_example.rs
):
use HtmlError;
use markdown_to_html_with_extensions;
Run the full style demo:
This will print out multiple styled examples (custom blocks, images, tables, bullet lists, code blocks, etc.) and show how they render as HTML.
Bringing It All Together
If you’d like to combine accessibility features and custom Markdown styling, you can configure your HtmlConfig
to enable:
- Syntax highlighting
- ARIA attribute generation
- Custom block parsing
- Emoji support
…thereby providing a powerful, end-to-end Markdown-to-HTML transformation pipeline suitable for high-performance, semantically rich, and user-friendly content.
Performance Characteristics
Document Scale | Processing Time | Memory Utilization |
---|---|---|
Small (<1KB) | ~0.1ms | Constant O(1) |
Medium (10KB) | ~1ms | Linear O(n) |
Large (100KB) | ~10ms | Linear O(n) |
Platform Support
Platform | Status | Rust Version | Notes |
---|---|---|---|
Linux | ✅ Fully | 1.56+ | Comprehensive support |
macOS | ✅ Fully | 1.56+ | Native performance |
Windows | ✅ Fully | 1.56+ | Complete compatibility |
WebAssembly | ⚠️ Partial | 1.56+ | Limited feature support |
Continuous Integration
We use GitHub Actions for comprehensive testing:
- Cross-platform compatibility checks
- Extensive test coverage
Conversion Error Handling
# use ;
# use HtmlError;
#
Running Examples
# Basic example
# Accessibility demo
# Performance benchmark
Contributing
We welcome contributions! See CONTRIBUTING.md for details on:
- Reporting issues
- Suggesting features
- Submitting pull requests
Licensing
Dual-licensed: Apache 2.0 & MIT
Acknowledgements
Special thanks to the Rust community and open-source contributors.