From 2605ae1fbe8a89c4ebc4579ce2bb1e5f9dfda186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Mon, 4 Oct 2021 20:37:46 +0200 Subject: [PATCH] parse #tags as links (resolve #8) --- src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7f19f09..c17acb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -502,7 +502,7 @@ fn preprocess_markdown(string: String) -> String { let finder = LinkFinder::new(); let result = double_brackets - .replace_all(string.as_str(), |caps: &Captures| { + .replace_all(&string, |caps: &Captures| { format!( "[{}]({})", &caps[1], @@ -511,6 +511,17 @@ fn preprocess_markdown(string: String) -> String { }) .to_string(); + let tags = Regex::new(r"#([\w]+)").unwrap(); + let result = tags + .replace_all(&result, |caps: &Captures| { + format!( + "[{}]({})", + &caps[0], + utf8_percent_encode(&caps[1], percent_encoding::NON_ALPHANUMERIC) + ) + }) + .to_string(); + let result_vec = Vec::from(result.as_str()); let start_delims = vec![b'(', b'<']; let end_delims = vec![b')', b'>'];