rust parser ; yaaayy i can now claim this project as fast.
This commit is contained in:
8
fastmd/Cargo.toml
Normal file
8
fastmd/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "fastmd"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
author = "rattatwinko"
|
||||
|
||||
[dependencies]
|
||||
pulldown-cmark = "0.13.0"
|
||||
37
fastmd/src/main.rs
Normal file
37
fastmd/src/main.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user