From b72d43b2509ccc0147f1987ad260d27e1e25e1ad Mon Sep 17 00:00:00 2001 From: deadvey Date: Thu, 9 Jan 2025 00:47:29 +0000 Subject: [PATCH] Sublists work now --- src/main.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 836020c..7c682c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,16 +60,20 @@ fn parse_markdown(page_content: String) -> (String, Vec) { // Block quotes let block_quotes_regex = Regex::new(r"^>(.*)").unwrap(); parsed_line = block_quotes_regex.replace_all(&parsed_line, |caps: ®ex::Captures| { - format!(" | {}", &caps[1].on_black()) + format!(" | {}", &caps[1]) }).to_string(); // Ordered list - let ordered_list_regex = Regex::new(r"^([0-9]+)\.(.*)").unwrap(); - parsed_line = ordered_list_regex.replace_all(&parsed_line, " $1. $2").to_string(); + let ordered_list_regex = Regex::new(r"^([ \t]+|^)([0-9]+)\. (.*)").unwrap(); + parsed_line = ordered_list_regex.replace_all(&parsed_line, |caps: ®ex::Captures| { + format!("{} {}. {}", &caps[1], &caps[2], &caps[3]) + }).to_string(); - // Unordered list - let unordered_list_regex = Regex::new(r"^(-|\+|\*).(.*)").unwrap(); - parsed_line = unordered_list_regex.replace_all(&parsed_line, " • $2").to_string(); + // Unordered list ([ ]+|^)- (.*) + let unordered_list_regex = Regex::new(r"^([ \t]+|^)(-|\+|\*).(.*)").unwrap(); + parsed_line = unordered_list_regex.replace_all(&parsed_line, |caps: ®ex::Captures| { + format!("{} • {}", &caps[1], &caps[3]) + }).to_string(); // Inline code let inline_code_regex = Regex::new(r"`(.*?)`").unwrap();