commit 0593c034c98c961e586f628d5a9f306c2561a162 Author: Logan Date: Thu Sep 5 02:04:45 2024 -0500 Initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6036a2c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,127 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "markdown" +version = "1.0.0-alpha.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "911a8325e6fb87b89890cd4529a2ab34c2669c026279e61c26b7140a3d821ccb" +dependencies = [ + "unicode-id", +] + +[[package]] +name = "mdconvert" +version = "0.1.0" +dependencies = [ + "markdown", + "walkdir", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "unicode-id" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1b6def86329695390197b82c1e244a54a131ceb66c996f2088a3876e2ae083f" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..ffe8791 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "mdconvert" +version = "0.1.0" +edition = "2021" + +[dependencies] +markdown = "1.0.0-alpha.20" +walkdir = "2.5" diff --git a/README.md b/README.md new file mode 100644 index 0000000..6c8114d --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Simple build script that converts markdown files to HTML. diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..5731307 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,39 @@ +use markdown::*; +use std::ffi::OsStr; +use std::{io::prelude::*, path::PathBuf}; + +fn convert_file( + entry: PathBuf, + head: &str, + opts: &Options, +) -> Result<(), std::io::Error> { + let md_file = std::fs::read_to_string(&entry)?; + let html_str = to_html_with_options(&md_file, &opts) + .map_err(|_| std::io::Error::new(std::io::ErrorKind::Other, ""))?; + let html_str = format!( + "{}
{}
", + head, html_str + ); + let mut html_path = entry.clone(); + html_path.set_extension("html"); + let mut html_file = std::fs::File::create(html_path)?; + html_file.write(html_str.as_bytes())?; + Ok(()) +} + +fn main() { + let mut opts = Options::gfm(); + opts.compile.allow_dangerous_html = true; + opts.compile.allow_dangerous_protocol = true; + let head = std::fs::read_to_string("./head").unwrap_or("".to_owned()); + + for entry in walkdir::WalkDir::new("./") { + let entry = match entry { + Ok(e) => e.into_path(), + Err(_) => continue, + }; + if entry.extension() == Some(OsStr::new("md")) { + convert_file(entry, &head, &opts).unwrap(); + } + } +} diff --git a/src/test.html b/src/test.html new file mode 100644 index 0000000..01845df --- /dev/null +++ b/src/test.html @@ -0,0 +1,2 @@ +

hello world

+
\ No newline at end of file diff --git a/src/test.md b/src/test.md new file mode 100644 index 0000000..2be7c65 --- /dev/null +++ b/src/test.md @@ -0,0 +1 @@ +# hello world