#markdown-html #markdown #syntax-highlighting #html #markdown-tables #generator #markdown-parser

mdx-gen

A robust Rust library for processing Markdown and converting it to HTML with support for custom blocks, enhanced table formatting, and flexible configuration options

1 unstable release

0.0.1 Sep 30, 2024

#29 in #markdown-tables

Download history 192/week @ 2024-09-30 87/week @ 2024-10-07 30/week @ 2024-10-14 80/week @ 2024-10-21 45/week @ 2024-10-28 157/week @ 2024-11-04 83/week @ 2024-11-11 32/week @ 2024-11-18 147/week @ 2024-11-25 60/week @ 2024-12-02 107/week @ 2024-12-09

348 downloads per month
Used in 5 crates (via html-generator)

MIT/Apache

45KB
667 lines

MDX Gen logo

MDX Generator (mdx-gen)

A robust Rust library for processing Markdown into responsive HTML, offering custom blocks, syntax highlighting, and enhanced table formatting for richer content.

Made With Love Crates.io Lib.rs Docs.rs License

WebsiteDocumentationReport BugRequest FeatureContributing Guidelines

Overview

mdx-gen is a flexible Rust library that converts Markdown into HTML, providing enhanced features like custom block extensions, syntax highlighting, and table formatting.

mdx-gen uses the high-performance comrak library for Markdown parsing and offers flexible options for modifying and extending Markdown behavior.

Key Features

  • Markdown to HTML Conversion: Converts Markdown to responsive HTML using the comrak parser, ensuring fast and accurate rendering of Markdown content.
  • Custom Block Extensions: Allows the use of custom blocks such as notes, warnings, and tips, transforming them into structured HTML elements for improved content formatting.
  • Syntax Highlighting: Automatically applies syntax highlighting to code blocks for a wide range of programming languages, making code snippets more readable and professional.
  • Enhanced Table Formatting: Converts Markdown tables into responsive HTML tables with proper alignment and additional styling for better usability across devices.
  • Flexible Configuration: Provides a customizable MarkdownOptions structure that allows developers to enable or disable specific features (e.g., custom blocks, enhanced tables, or syntax highlighting).
  • Error Handling: Comprehensive error handling system with detailed error reporting to ensure smooth Markdown processing, even in complex cases.

Supported Extensions

mdx-gen offers the following extensions, which can be enabled or disabled individually via MarkdownOptions:

  • Custom blocks (notes, warnings, tips)
  • Enhanced table formatting with responsive design
  • Syntax highlighting for code blocks
  • Strikethrough and autolink support
  • Advanced error reporting for improved debugging

Installation

Add this to your Cargo.toml:

[dependencies]
mdx-gen = "0.0.1"

Usage

Here are some examples of how to use the library:

Basic Usage

use mdx_gen::{process_markdown, MarkdownOptions};

let markdown_content = "# Hello, world!\n\nThis is a paragraph.";
let options = MarkdownOptions::new()
    .with_enhanced_tables(false);
let html = process_markdown(markdown_content, &options).unwrap();
println!("HTML output: {}", html);

Custom Blocks and Syntax Highlighting

use mdx_gen::{process_markdown, MarkdownOptions};

let markdown_content = r#"
# Example

<div class="note">This is a note.</div>

``rust
fn main() {
    println!("Hello, world!");
}
"#;

let options = MarkdownOptions::new()
    .with_custom_blocks(true)
    .with_syntax_highlighting(true)
    .with_enhanced_tables(true)
    .with_comrak_options({
        let mut opts = comrak::ComrakOptions::default();
        opts.extension.table = true;
        opts
    });

let html = process_markdown(markdown_content, &options).unwrap();
println!("HTML output: {}", html);

Modules

  • lib.rs: The main library module that ties everything together.
  • markdown.rs: Core functionality for Markdown processing and conversion.
  • extensions.rs: Handles custom block extensions, syntax highlighting, and table processing.
  • error.rs: Defines error types and implements error handling for the library.

Documentation

For full API documentation, please visit docs.rs/mdx-gen.

Examples

To run the examples, clone the repository and use the following command:

cargo run --example example_name

Replace example_name with the name of the example you want to run.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

License

The project is dual-licensed under the terms of both the MIT license and the Apache License (Version 2.0).

at your option.

Acknowledgements

Special thanks to all contributors who have helped build the mdx-gen library.

Dependencies

~9–20MB
~312K SLoC