use std::{env, fs, process};
use pulldown_cmark::{Parser, Options, html};

fn main() {
    // Get the file path from CLI args
    let args: Vec<String> = env::args().collect();
    if args.len() != 2 {
        eprintln!("Usage: {} <markdown_file>", args[0]);
        process::exit(1);
    }

    let path = &args[1];

    // Read file contents
    let markdown = match fs::read_to_string(path) {
        Ok(content) => content,
        Err(e) => {
            eprintln!("Error reading {}: {}", path, e);
            process::exit(1);
        }
    };

    // Configure parser with GitHub-flavored options
    let mut options = Options::empty();
    options.insert(Options::ENABLE_TABLES);
    options.insert(Options::ENABLE_FOOTNOTES);
    options.insert(Options::ENABLE_STRIKETHROUGH);
    options.insert(Options::ENABLE_TASKLISTS);

    // Parse and render to HTML
    let parser = Parser::new_ext(&markdown, options);
    let mut html_output = String::new();
    html::push_html(&mut html_output, parser);

    // Print only the body content (no <html>/<head>)
    println!("{} <!-- this was generated from rust with pulldown_cmark ; REASON: Large File -->", html_output);
}
