Can you write me a nice README.md file for this project. It's called omd.…
- User
Can you write me a nice README.md file for this project. It's called omd.
#![allow(warnings)] use base64::encode; use notify::Watcher; use std::fs::File; use std::io::{self, Read, Write}; use std::path::PathBuf;
use clap::Parser; use futures_util::stream::{Stream, StreamExt}; use pulldown_cmark::{html, Event, Options, Parser as MdParser}; use std::pin::Pin; use tokio::sync::{broadcast, RwLock}; use warp::{sse, Filter};
use std::sync::Arc;
#[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { #[arg(value_name = "FILE")] file: Option,
code#[arg(short, long)] static_mode: bool,}
#[tokio::main] async fn main() -> io::Result<()> { // Parse command-line arguments let args = Args::parse();
codeif args.static_mode { run_static_mode(&args)?; } else { run_server_mode(&args).await?; } Ok(())}
fn run_static_mode(args: &Args) -> io::Result<()> { // Read Markdown content let (file_name, markdown_input) = match &args.file { Some(file_path) => { let mut file = File::open(&file_path).unwrap_or_else(|err| { eprintln!("Error opening file {}: {}", file_path.display(), err); std::process::exit(1); }); let mut content = String::new(); file.read_to_string(&mut content)?; ( file_path.file_name().unwrap().to_string_lossy().to_string(), content, ) } None => { // Read from stdin if no file is provided let mut content = String::new(); io::stdin().read_to_string(&mut content)?; (String::from("New file"), content) } };
codelet html_output = render_markdown_to_html(&markdown_input); let style = read_style_css(); let fonts = read_fonts(); let html_content = build_full_html(&file_name, &html_output, &style, &fonts, false); // Create a temporary file with .html extension let temp_file = tempfile::Builder::new() .prefix("markdown_preview_") .suffix(".html") .rand_bytes(5) .tempfile()?; let temp_path = temp_file.path().to_string_lossy().to_string(); open_in_browser(temp_path); // Write HTML content to the temporary file let mut file = temp_file.as_file(); file.write_all(html_content.as_bytes())?; file.flush()?; // Open the default browser // Keep the program running to prevent the temporary file from being deleted println!("Press Enter to exit..."); let mut input = String::new(); io::stdin().read_line(&mut input)?; Ok(()) - Assistant