html_generator

Function markdown_file_to_html

Source
pub fn markdown_file_to_html(
    input: Option<impl AsRef<Path>>,
    output: Option<OutputDestination>,
    config: Option<MarkdownConfig>,
) -> Result<()>
Expand description

Converts a Markdown file to HTML.

This function reads from a file or stdin and writes the generated HTML to a specified destination. It handles encoding/decoding of content.

§Arguments

  • input - The input source (file path or None for stdin)
  • output - The output destination (defaults to stdout)
  • config - Optional configuration including encoding settings

§Returns

Returns Result<()> indicating success or failure of the operation.

§Errors

Returns an error if:

  • Input file is not found or cannot be read
  • Output file cannot be written
  • Configuration is invalid
  • Input size exceeds configured maximum

§Examples

use html_generator::{markdown_file_to_html, OutputDestination, MarkdownConfig};
use std::path::{Path, PathBuf};

// Convert file to HTML and write to stdout
markdown_file_to_html(
    Some(PathBuf::from("input.md")),
    None,
    None,
)?;

// Convert stdin to HTML file
markdown_file_to_html(
    None::<PathBuf>,  // Explicit type annotation
    Some(OutputDestination::File("output.html".into())),
    Some(MarkdownConfig::default()),
)?;