render_html

Function render_html 

Source
pub fn render_html(ast: &Document, config: Config) -> String
Expand description

Render a Markdown AST to semantic HTML

This function takes a parsed Markdown document (AST) and converts it to clean, standards-compliant HTML. The output includes proper semantic markup, accessibility features, and support for all CommonMark + GFM elements.

§Arguments

  • ast - The Markdown document AST to render
  • config - Configuration options controlling the HTML output

§Returns

A String containing the generated HTML

§Examples

Basic HTML rendering:

use markdown_ppp::ast::*;
use markdown_ppp::html_printer::{render_html, config::Config};

let doc = Document {
    blocks: vec![
        Block::Heading(Heading {
            kind: HeadingKind::Atx(1),
            content: vec![Inline::Text("Title".to_string())],
        }),
        Block::Paragraph(vec![
            Inline::Text("Text with ".to_string()),
            Inline::Strong(vec![Inline::Text("emphasis".to_string())]),
        ]),
    ],
};

let config = Config::default();
let html = render_html(&doc, config);

assert!(html.contains("<h1>Title</h1>"));
assert!(html.contains("emphasis"));

§HTML Features

The renderer produces:

  • Semantic HTML5 elements (<article>, <section>, <aside>, etc.)
  • Proper heading hierarchy (<h1> through <h6>)
  • Accessible tables with <thead>, <tbody>, and proper scoping
  • Code syntax highlighting preparation with language classes
  • Task list checkboxes with proper disabled attributes
  • Footnote links with proper aria-describedby attributes
  • GitHub Alert styling with appropriate CSS classes

§Security

All user content is properly escaped to prevent XSS attacks. HTML content in the AST is preserved as-is (assumed to be trusted).