html-generator 0.0.4

A robust Rust library designed for transforming Markdown into SEO-optimized, accessible HTML. Featuring front matter extraction, custom header processing, table of contents generation, and performance optimization for web projects of any scale.
Documentation
//! # Batch Processing Markdown to HTML Example
//!
//! This example showcases the functionality of the `html-generator` library by
//! converting Markdown content from multiple sources into HTML.
//!
//! ## Features Highlighted
//! - Processes Markdown from a variety of sources, including basic and extended features.
//! - Displays the HTML output for each source.

use html_generator::{generate_html, HtmlConfig};
use std::collections::HashMap;

/// Entry point for the batch processing Markdown to HTML example.
///
/// Demonstrates conversion of Markdown from multiple sources into HTML.
///
/// # Errors
/// Returns an error if any Markdown to HTML conversion fails.
fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("\n๐Ÿฆ€ Welcome to the Batch Processing Markdown to HTML Example!");
    println!("================================================================");

    // Markdown sources from the `./basic` folder
    let basic_sources: HashMap<&str, &str> = vec![
        (
            "๐Ÿ“ Amps and Angle Encoding",
            include_str!("./basic/amps-and-angle-encoding.txt"),
        ),
        (
            "๐Ÿ”— Angle Links and Images",
            include_str!("./basic/angle-links-and-img.txt"),
        ),
        ("๐ŸŒ Auto Links", include_str!("./basic/auto-links.txt")),
        (
            "๐ŸŽฏ Backlash Escapes",
            include_str!("./basic/backlash-escapes.txt"),
        ),
        (
            "๐Ÿ“œ Blockquotes with Code Blocks",
            include_str!("./basic/blockquotes-with-code-blocks.txt"),
        ),
        (
            "๐Ÿ’ก Code Syntax Highlighting",
            include_str!("./basic/code_syntax_highlighting.txt"),
        ),
        (
            "๐Ÿ”ข Code Block in List",
            include_str!("./basic/codeblock-in-list.txt"),
        ),
        (
            "๐Ÿ“ฆ Custom Containers",
            include_str!("./basic/custom_containers.txt"),
        ),
        ("๐Ÿ•ต๏ธโ€โ™‚๏ธ Edge Cases", include_str!("./basic/edge_cases.txt")),
        (
            "๐Ÿ˜€ Emoji Content",
            include_str!("./basic/emoji_content.txt"),
        ),
        (
            "๐Ÿšฉ Escaped Characters",
            include_str!("./basic/escaped_characters.txt"),
        ),
        (
            "โฉ Hard Wrapped Lines",
            include_str!("./basic/hard-wrapped.txt"),
        ),
        (
            "โค Horizontal Rules",
            include_str!("./basic/horizontal-rules.txt"),
        ),
        (
            "๐Ÿ“š Large Markdown File",
            include_str!("./basic/large_markdown.txt"),
        ),
        ("๐Ÿ”— Inline Links", include_str!("./basic/links-inline.txt")),
        (
            "๐Ÿ“– Reference Links",
            include_str!("./basic/links-reference.txt"),
        ),
        (
            "๐Ÿ—จ๏ธ Literal Quotes",
            include_str!("./basic/literal-quotes.txt"),
        ),
        (
            "๐Ÿ“š Markdown Basics",
            include_str!("./basic/markdown-documentation-basics.txt"),
        ),
        (
            "๐Ÿ“˜ Markdown Syntax",
            include_str!("./basic/markdown-syntax.txt"),
        ),
        (
            "๐Ÿ—จ๏ธ Nested Blockquotes",
            include_str!("./basic/nested-blockquotes.txt"),
        ),
        (
            "๐Ÿ”ข Ordered and Unordered Lists",
            include_str!("./basic/ordered-and-unordered-list.txt"),
        ),
        (
            "๐Ÿ’ช Strong and Emphasis Together",
            include_str!("./basic/strong-and-em-together.txt"),
        ),
        ("๐Ÿ—‚๏ธ Tabs", include_str!("./basic/tabs.txt")),
        ("๐Ÿงน Tidiness", include_str!("./basic/tidyness.txt")),
    ]
    .into_iter()
    .collect();

    // Markdown sources from the `./extensions` folder
    let extensions_sources: HashMap<&str, &str> = vec![
        ("๐Ÿ“˜ Admonition", include_str!("./extensions/admonition.txt")),
        (
            "โš™๏ธ Attribute List",
            include_str!("./extensions/attr_list.txt"),
        ),
        ("โœจ Codehilite", include_str!("./extensions/codehilite.txt")),
        (
            "๐Ÿ™ GitHub Flavored Markdown",
            include_str!("./extensions/github_flavored.txt"),
        ),
        (
            "๐ŸŒŸ NL2BR with Attribute List",
            include_str!("./extensions/nl2br_w_attr_list.txt"),
        ),
        ("๐Ÿ“‹ Sane Lists", include_str!("./extensions/sane_lists.txt")),
        (
            "๐Ÿ—‚๏ธ Table of Contents (TOC)",
            include_str!("./extensions/toc.txt"),
        ),
        (
            "๐Ÿšจ TOC Invalid",
            include_str!("./extensions/toc_invalid.txt"),
        ),
        (
            "๐Ÿ“„ TOC Nested List",
            include_str!("./extensions/toc_nested_list.txt"),
        ),
        ("๐Ÿ“‚ TOC Nested", include_str!("./extensions/toc_nested.txt")),
    ]
    .into_iter()
    .collect();

    // Markdown sources from the `./misc` folder
    let misc_sources: HashMap<&str, &str> = vec![
        (
            "โš™๏ธ CRLF Line Ends",
            include_str!("./misc/CRLF_line_ends.txt"),
        ),
        (
            "๐Ÿ”— Adjacent Headers",
            include_str!("./misc/adjacent-headers.txt"),
        ),
        ("๐ŸŒ Arabic", include_str!("./misc/arabic.txt")),
        (
            "๐Ÿ”— Autolinks with Asterisks",
            include_str!("./misc/autolinks_with_asterisks.txt"),
        ),
        (
            "๐Ÿ‡ท๐Ÿ‡บ Autolinks with Asterisks (Russian)",
            include_str!("./misc/autolinks_with_asterisks_russian.txt"),
        ),
        (
            "๐Ÿท๏ธ Backtick Escape",
            include_str!("./misc/backtick-escape.txt"),
        ),
        ("๐Ÿ”„ Bidi", include_str!("./misc/bidi.txt")),
        (
            "๐Ÿ“œ Blank Block Quote",
            include_str!("./misc/blank-block-quote.txt"),
        ),
        (
            "๐Ÿ”ฒ Blank Lines in Codeblocks",
            include_str!("./misc/blank_lines_in_codeblocks.txt"),
        ),
        (
            "๐Ÿ–‹๏ธ Blockquote Below Paragraph",
            include_str!("./misc/blockquote-below-paragraph.txt"),
        ),
        (
            "โค Blockquote Horizontal Rule",
            include_str!("./misc/blockquote-hr.txt"),
        ),
        ("๐Ÿ—จ๏ธ Blockquote", include_str!("./misc/blockquote.txt")),
        ("๐Ÿ”— Bold Links", include_str!("./misc/bold_links.txt")),
        ("โŽ Line Break", include_str!("./misc/br.txt")),
        (
            "๐Ÿ”Ž Bracket Regular Expression",
            include_str!("./misc/bracket_re.txt"),
        ),
        (
            "๐Ÿ–ผ๏ธ Brackets in Image Title",
            include_str!("./misc/brackets-in-img-title.txt"),
        ),
        (
            "๐Ÿ–‹๏ธ Code First Line",
            include_str!("./misc/code-first-line.txt"),
        ),
        (
            "๐Ÿ”— Emphasis Around Links",
            include_str!("./misc/em-around-links.txt"),
        ),
        (
            "๐Ÿ’ช Emphasis and Strong",
            include_str!("./misc/em_strong.txt"),
        ),
        (
            "๐Ÿ’ก Complex Emphasis and Strong",
            include_str!("./misc/em_strong_complex.txt"),
        ),
        ("๐Ÿ“ง Email", include_str!("./misc/email.txt")),
        ("๐Ÿ”— Escaped Links", include_str!("./misc/escaped_links.txt")),
        ("๐Ÿ“‹ Funky List", include_str!("./misc/funky-list.txt")),
        ("#๏ธโƒฃ H1", include_str!("./misc/h1.txt")),
        ("#๏ธโƒฃ Hash", include_str!("./misc/hash.txt")),
        (
            "๐Ÿ—‚๏ธ Header in Lists",
            include_str!("./misc/header-in-lists.txt"),
        ),
        ("#๏ธโƒฃ Headers", include_str!("./misc/headers.txt")),
        ("โค Horizontal Line", include_str!("./misc/hline.txt")),
        ("๐Ÿ–ผ๏ธ Image 2", include_str!("./misc/image-2.txt")),
        (
            "๐Ÿ”— Image in Links",
            include_str!("./misc/image_in_links.txt"),
        ),
        (
            "โœ๏ธ Insert at Start of Paragraph",
            include_str!("./misc/ins-at-start-of-paragraph.txt"),
        ),
        ("๐Ÿ“„ Inside HTML", include_str!("./misc/inside_html.txt")),
        ("๐Ÿ‡ฏ๐Ÿ‡ต Japanese", include_str!("./misc/japanese.txt")),
        (
            "๐Ÿ—จ๏ธ Lazy Blockquote",
            include_str!("./misc/lazy-block-quote.txt"),
        ),
        (
            "๐Ÿ”— Link with Parenthesis",
            include_str!("./misc/link-with-parenthesis.txt"),
        ),
        ("๐Ÿ—‚๏ธ Lists", include_str!("./misc/lists.txt")),
        ("๐Ÿ—‚๏ธ Lists 2", include_str!("./misc/lists2.txt")),
        ("๐Ÿ—‚๏ธ Lists 3", include_str!("./misc/lists3.txt")),
        ("๐Ÿ—‚๏ธ Lists 4", include_str!("./misc/lists4.txt")),
        ("๐Ÿ—‚๏ธ Lists 5", include_str!("./misc/lists5.txt")),
        ("๐Ÿ—‚๏ธ Lists 6", include_str!("./misc/lists6.txt")),
        ("๐Ÿ—‚๏ธ Lists 7", include_str!("./misc/lists7.txt")),
        ("๐Ÿ—‚๏ธ Lists 8", include_str!("./misc/lists8.txt")),
        (
            "๐Ÿ”— Missing Link Definition",
            include_str!("./misc/missing-link-def.txt"),
        ),
        (
            "๐Ÿ—จ๏ธ Multi-paragraph Blockquote",
            include_str!("./misc/multi-paragraph-block-quote.txt"),
        ),
        ("๐Ÿงช Multi Test", include_str!("./misc/multi-test.txt")),
        ("๐Ÿ—‚๏ธ Nested Lists", include_str!("./misc/nested-lists.txt")),
        (
            "๐Ÿ” Nested Patterns",
            include_str!("./misc/nested-patterns.txt"),
        ),
        ("๐Ÿ› ๏ธ Normalize", include_str!("./misc/normalize.txt")),
        (
            "#๏ธโƒฃ Numeric Entity",
            include_str!("./misc/numeric-entity.txt"),
        ),
        (
            "๐Ÿ–‹๏ธ Paragraph with Horizontal Rule",
            include_str!("./misc/para-with-hr.txt"),
        ),
        ("๐Ÿ‡ท๐Ÿ‡บ Russian", include_str!("./misc/russian.txt")),
        ("๐Ÿ’ก Smart Emphasis", include_str!("./misc/smart_em.txt")),
        ("๐Ÿงช Some Test", include_str!("./misc/some-test.txt")),
        ("๐Ÿ–‹๏ธ Span", include_str!("./misc/span.txt")),
        (
            "๐Ÿ’ช Strong with Underscores",
            include_str!("./misc/strong-with-underscores.txt"),
        ),
        ("๐Ÿ’ช Strong in Tags", include_str!("./misc/stronintags.txt")),
        ("๐Ÿ”ข Tabs in Lists", include_str!("./misc/tabs-in-lists.txt")),
        ("โฉ Two Spaces", include_str!("./misc/two-spaces.txt")),
        ("๐Ÿ’ก Uche", include_str!("./misc/uche.txt")),
        ("๐Ÿ”— Underscores", include_str!("./misc/underscores.txt")),
        ("๐ŸŒ URL with Spaces", include_str!("./misc/url_spaces.txt")),
    ]
    .into_iter()
    .collect();

    // Process each group of sources
    println!("\n๐Ÿ“‚ Processing Markdown from the `./basic` folder");
    process_sources("๐Ÿ“„ Basic Features", basic_sources)?;

    println!("\n๐Ÿ“‚ Processing Markdown from the `./extensions` folder");
    process_sources("๐Ÿงฉ Extended Features", extensions_sources)?;

    println!("\n๐Ÿ“‚ Processing Markdown from the `./misc` folder");
    process_sources("๐Ÿ” Miscellaneous Features", misc_sources)?;

    println!("\n๐ŸŽ‰ Batch processing example completed successfully!");

    Ok(())
}

/// Processes a group of Markdown sources and generates HTML for each.
fn process_sources(
    group_name: &str,
    sources: HashMap<&str, &str>,
) -> Result<(), Box<dyn std::error::Error>> {
    println!("\n๐Ÿ—‚๏ธ Group: {group_name}");
    println!(
        "----------------------------------------------------------"
    );

    let config = HtmlConfig::default();

    for (title, markdown) in sources {
        println!("\n๐Ÿ“ Processing: {title}");
        println!("----------------------------------------------------------");

        // Generate HTML from Markdown
        match generate_html(markdown, &config) {
            Ok(html) => {
                println!(
                    "    โœ… Successfully generated HTML:\n{}",
                    html
                );
            }
            Err(e) => {
                println!("    โŒ Failed to generate HTML: {}", e);
            }
        }
    }

    Ok(())
}