diff options
Diffstat (limited to 'src/matrix.rs')
| -rw-r--r-- | src/matrix.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/matrix.rs b/src/matrix.rs index 47fa984..cebddfd 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -14,13 +14,14 @@ const MATRIX_FORMATS: &[(&'static str, (&'static str, &'static str))] = &[ ]; #[pyfunction] -pub fn format_for_matrix(body: String) -> PyResult<String> { +pub fn format_for_matrix(body: String, mentions: Option<Vec<(String, usize, usize)>>) -> PyResult<String> { let mut chars: Vec<char> = body.chars().collect(); if chars.len() < 1 { return Ok(body); } - let styles: Vec<(String, usize, usize, usize, usize)> = parse_with_limits(&chars, 0, chars.len() - 1, 0); + let mentions = mentions.unwrap_or(Vec::with_capacity(0)); + let styles: Vec<(String, usize, usize, usize, usize)> = parse_with_limits(&chars, 0, chars.len() - 1, 0); let mut tags: Vec<(usize, String, usize)> = Vec::with_capacity(styles.len() * 2); for (keyword, start, remove_start, end, remove_end) in styles { if MATRIX_FORMATS.iter().any(|&(k, _)| k == keyword) { @@ -30,14 +31,18 @@ pub fn format_for_matrix(body: String) -> PyResult<String> { .into_iter() .collect::<String>()) } else { - MATRIX_FORMATS.iter().find(|&&(k, _)| k == keyword).unwrap().1.0.clone().to_string() + MATRIX_FORMATS.iter().find(|&&(k, _)| k == keyword).unwrap().1.0.clone().to_owned() }; tags.push((start, opening_tag, remove_start)); - tags.push((end, MATRIX_FORMATS.iter().find(|&&(k, _)| k == keyword).unwrap().1.1.clone().to_string(), remove_end)); + tags.push((end, MATRIX_FORMATS.iter().find(|&&(k, _)| k == keyword).unwrap().1.1.clone().to_owned(), remove_end)); } else if keyword == ">>" || keyword == "```>" || keyword == "\\" { - tags.push((start, "".to_string(), start+1)); + tags.push((start, String::new(), start+1)); } } + for (mxid, start, end) in mentions { + tags.push((start, "<a href='https://matrix.to/#/".to_owned() + &mxid + "'>", start)); + tags.push((end, "</a>".to_owned(), end)); + } tags.sort_by(|a, b| b.0.cmp(&a.0)); |
