diff --git a/PyPost.py b/PyPost.py index e889782..16f0579 100644 --- a/PyPost.py +++ b/PyPost.py @@ -126,7 +126,7 @@ def render_markdown(md_path: Path):
-

+

Back {title}

@@ -295,7 +295,7 @@ if __name__ == "__main__": # Update threshold if specified RUST_PARSER_THRESHOLD = args.rust_threshold - Logger.log_obfuscation_info(f"Obfuscation is {'enabled' if obfuscate else 'disabled'}", obfuscate) + Logger.log_obfuscation_info(f"Obfuscation is {obfuscate}",obfuscate) initial_scan(MARKDOWN_DIR) event_handler = Handler() diff --git a/fastmd/src/main.rs b/fastmd/src/main.rs index 9c90518..46282af 100644 --- a/fastmd/src/main.rs +++ b/fastmd/src/main.rs @@ -1,37 +1,82 @@ use std::{env, fs, process}; use pulldown_cmark::{Parser, Options, html}; +use std::path::PathBuf; -fn main() { - // Get the file path from CLI args - let args: Vec = env::args().collect(); - if args.len() != 2 { - eprintln!("Usage: {} ", args[0]); - process::exit(1); +#[derive(Debug)] +enum MarkdownError { + IoError(std::io::Error), + InvalidArgs, + InvalidFileType, +} + +impl From for MarkdownError { + fn from(err: std::io::Error) -> Self { + MarkdownError::IoError(err) } +} - 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); +impl std::fmt::Display for MarkdownError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + MarkdownError::IoError(e) => write!(f, "IO error: {}", e), + MarkdownError::InvalidArgs => write!(f, "Invalid arguments provided"), + MarkdownError::InvalidFileType => write!(f, "File extension should be .md or .markdown"), } - }; + } +} - // Configure parser with GitHub-flavored options +fn markdown_to_html(markdown: &str, body_top_content: &str) -> String { 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 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 /) - println!("{} ", html_output); + + // If body_top_content is not empty, wrap the output + if !body_top_content.trim().is_empty() { + format!("{}\n{}", body_top_content, html_output) + } else { + html_output + } +} + +fn validate_file_type(path: &PathBuf) -> Result<(), MarkdownError> { + if let Some(ext) = path.extension() { + if ext == "md" || ext == "markdown" { + Ok(()) + } else { + Err(MarkdownError::InvalidFileType) + } + } else { + Err(MarkdownError::InvalidFileType) + } +} + +fn run() -> Result { + let args: Vec = env::args().collect(); + if args.len() != 2 { + return Err(MarkdownError::InvalidArgs); + } + + let path = PathBuf::from(&args[1]); + validate_file_type(&path)?; + let markdown = fs::read_to_string(&path)?; + let top_content = ""; + Ok(markdown_to_html(&markdown, top_content)) +} + +fn main() { + match run() { + Ok(html_output) => { + println!("{}", html_output); + } + Err(e) => { + eprintln!("Error: {}", e); + process::exit(1); + } + } } diff --git a/html/base/index.html b/html/base/index.html index 9472cc8..2b4cd29 100644 --- a/html/base/index.html +++ b/html/base/index.html @@ -10,7 +10,7 @@ #available { padding-left: 40px;} ul { padding-left: 100px;} #nojs { display: inline-block;color: red;transition: transform 0.7s cubic-bezier(0.215, 0.610, 0.355, 1); } - #nojs:hover { transform: skewX(-12deg);} + /*#nojs:hover { transform: skewX(-12deg);}*/ #nonenormalul { list-style: disc inside; margin: 1em 0; padding-left: 40px; background: none; } #nonenormalul li { list-style: inherit; margin: 0; padding: 0; background: none; transition: font-size 0.5s cubic-bezier(0.075, 0.82, 0.165, 1); } #nonenormalul li:hover { font-size: larger; } @@ -28,6 +28,7 @@
  • It strips the .HTML ending from each file you see in the list below
  • It isnt necessary, but visually tweaks the page.
  • +
  • It enables the "Back" Function for Headers

@@ -55,6 +56,5 @@

-