this was an old project, i patched it up and optimized it
This commit is contained in:
parent
15d117fb0d
commit
0bd2ec2af4
5 changed files with 283 additions and 0 deletions
43
src/main.rs
Normal file
43
src/main.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
use clap::{Arg, Command};
|
||||
use pulldown_cmark::{Parser, Options, html};
|
||||
use std::{fs::File, io::{self, Read, Write}};
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
// Define and parse command-line arguments using clap
|
||||
let matches = Command::new("jelly")
|
||||
.version("1.0")
|
||||
.author("conzie")
|
||||
.about("Converts a Markdown file to an HTML file")
|
||||
.arg(
|
||||
Arg::new("input")
|
||||
.help("The input Markdown file")
|
||||
.required(true)
|
||||
.index(1),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("output")
|
||||
.help("The output HTML file")
|
||||
.required(true)
|
||||
.index(2),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let input_path = matches.get_one::<String>("input").unwrap();
|
||||
let output_path = matches.get_one::<String>("output").unwrap();
|
||||
|
||||
let mut input_file = File::open(input_path)?;
|
||||
let mut markdown_content = String::new();
|
||||
input_file.read_to_string(&mut markdown_content)?;
|
||||
|
||||
let options = Options::empty();
|
||||
let parser = Parser::new_ext(&markdown_content, options);
|
||||
let mut html_output = String::new();
|
||||
html::push_html(&mut html_output, parser);
|
||||
|
||||
let mut output_file = File::create(output_path)?;
|
||||
output_file.write_all(html_output.as_bytes())?;
|
||||
|
||||
println!("Conversion successful! HTML written to: {}", output_path);
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue