From 8963b6f4d57e52ac32f1dc68e4424ff2df340d8e Mon Sep 17 00:00:00 2001 From: Luis Ball Date: Wed, 15 Dec 2021 13:12:19 -0500 Subject: [PATCH] fix(annotate): remove surrounding whitespace This commit removes the surrounding whitespace form the MD table PR titles. This fixes an issue where italizised and struckout titles were incorrectly formatted as a result of the extra white space. Co-authored-by: Frederick Fogerty --- src/persist.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/persist.rs b/src/persist.rs index 19cbc65..87e34b3 100644 --- a/src/persist.rs +++ b/src/persist.rs @@ -27,13 +27,17 @@ fn safe_replace(body: &str, table: &str) -> String { } } +/** + * Remove title prefixes from markdown table + */ fn remove_title_prefixes(row: String, prefix: &str) -> String { let prefix = String::from(prefix); let prefix_1 = &prefix[0..2]; let prefix_2 = &prefix[2..4]; - let regex_str = format!(r"{}[^\]]+{}\s*", prefix_1, prefix_2); + // Regex removes the prefix from the title and removes surrounding whitespace + let regex_str = format!(r"\s*{}[^\]]+{}\s*", prefix_1, prefix_2); let regex = Regex::new(®ex_str).unwrap(); - return regex.replace_all(&row, "").into_owned(); + return regex.replace_all(&row, "").trim().to_string().to_owned(); } pub async fn persist(