summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSavagePeanut <sourcehut@lazytapir.com>2023-09-03 21:27:07 -0500
committerSavagePeanut <sourcehut@lazytapir.com>2023-09-03 21:27:07 -0500
commitfbd5eeb993b4a934b6cb2598adbb67485e74f16b (patch)
treec41c81dcda03ad343563680b8eb2e3266a093d33
parentd8140d13e82f9b320e069b2e8b85cca93c8a7ac4 (diff)
add test case
-rw-r--r--src/matrix.rs3
-rw-r--r--tests/test_matrix.py4
2 files changed, 6 insertions, 1 deletions
diff --git a/src/matrix.rs b/src/matrix.rs
index 92d2eb8..963e569 100644
--- a/src/matrix.rs
+++ b/src/matrix.rs
@@ -46,7 +46,7 @@ pub fn format_for_matrix(body: String) -> PyResult<String> {
if tag == "</code></pre>" {
// index is at \n, add 1 to skip that one
let substring = chars[index + 1..replace_newlines_to].into_iter().collect::<String>();
- chars = [&chars[..index + 1], &substring.replace('\n', "<br>").chars().collect::<Vec<char>>()[..]].concat();
+ chars = [&chars[..index + 1], &substring.replace('\n', "<br>").chars().collect::<Vec<char>>()[..], &chars[replace_newlines_to..]].concat();
} else if tag == "<pre><code>" {
replace_newlines_to = index;
}
@@ -60,6 +60,7 @@ pub fn format_for_matrix(body: String) -> PyResult<String> {
} else {
replace_newlines_to - offset.abs() as usize
};
+ println!("chars {:?}", chars.clone().into_iter().collect::<String>());
}
let substring = chars[..replace_newlines_to].into_iter().collect::<String>();
let text = [substring.replace('\n', "<br>"), chars[replace_newlines_to..].into_iter().collect::<String>()].concat();
diff --git a/tests/test_matrix.py b/tests/test_matrix.py
index be33973..7dbafdc 100644
--- a/tests/test_matrix.py
+++ b/tests/test_matrix.py
@@ -227,6 +227,10 @@ def test_assorted():
formatted_body = "<em>underline</em> <strong>bold</strong> <strike>strikethrough</strike> >not quote <span data-mx-spoiler>spoiler</span><br><blockquote>quote</blockquote><br>nothing<br>nothing<br><blockquote><blockquote><blockquote><blockquote>another quote with <span data-mx-spoiler><strike><em><strong>```four```</strong></em></strike></span></blockquote></blockquote></blockquote></blockquote>"
assert(format_for_matrix(test) == formatted_body)
+ test = "```\nhacker\ncode\n```\n\n```\nhacker\ncode\n```"
+ formatted_body = "<pre><code>hacker\ncode</code></pre><br><br><pre><code>hacker\ncode</code></pre>"
+ assert(format_for_matrix(test) == formatted_body)
+
test = ">```\n>do be do be dooo ba do be do be do ba\n>>>"
formatted_body = "<blockquote><pre><code>do be do be dooo ba do be do be do ba\n>></code></pre></blockquote>"
assert(format_for_matrix(test) == formatted_body)