diff options
| author | SavagePeanut <sourcehut@lazytapir.com> | 2024-01-18 18:41:03 -0600 |
|---|---|---|
| committer | SavagePeanut <sourcehut@lazytapir.com> | 2024-01-18 18:41:03 -0600 |
| commit | 91987c153449ea8b8ecb55cbc5968669e35454cb (patch) | |
| tree | ef5f4856eadf54c7ed051bfeeb606caeba880133 | |
| parent | 1c6446aaa5842676f187287d2f84e34c318465a1 (diff) | |
fix empty styles
| -rw-r--r-- | src/parser.rs | 23 | ||||
| -rw-r--r-- | tests/test_matrix.py | 17 |
2 files changed, 27 insertions, 13 deletions
diff --git a/src/parser.rs b/src/parser.rs index 4f5ae58..0bf0f46 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -38,7 +38,7 @@ pub fn parse_with_limits(chars: &Vec<char>, start: usize, end: usize, depth: usi } match seek_end_block(chars, c, end_of_line, end, depth) { Some(to) => { - if to != index + 3 && is_quote_start(chars, index, depth) { + if to != end_of_line && is_quote_start(chars, index, depth) { let keyword = if end_of_line == index + 3 { "```".to_string() } else { @@ -170,7 +170,7 @@ fn seek_end(chars: &Vec<char>, keyword: char, start: usize, repetitions: usize, && !chars[i - 1].is_whitespace() && is_char_repeating(chars, keyword, repetitions, i + 1, end) { - match seek_higher_order_end(chars, c, i + 1, repetitions, end) { + match seek_higher_order_end(chars, c, i + 1, end) { Some(higher_order_i) => { return Some(higher_order_i); } @@ -183,24 +183,21 @@ fn seek_end(chars: &Vec<char>, keyword: char, start: usize, repetitions: usize, None } -fn seek_higher_order_end(chars: &Vec<char>, keyword: char, start: usize, repetitions: usize, end: usize) -> Option<usize> { +fn seek_higher_order_end(chars: &Vec<char>, keyword: char, start: usize, end: usize) -> Option<usize> { + let mut skip = true; for i in start..=end { let c = chars[i]; if c == '\n' { return None; } - if c == keyword - && chars[i - 1].is_whitespace() - && !followed_by_whitespace(chars, i, end) - && is_char_repeating(chars, keyword, repetitions, i + 1, end) - { + if c != keyword { + skip = false; + continue; + } + if chars[i - 1].is_whitespace() && !followed_by_whitespace(chars, i, end) { return None; // "*bold* *<--- beginning of new bold>*" } - if c == keyword - && !chars[i - 1].is_whitespace() - && followed_by_whitespace(chars, i, end) - && is_char_repeating(chars, keyword, repetitions, i + 1, end) - { + if followed_by_whitespace(chars, i, end) && !skip { return Some(i); } } diff --git a/tests/test_matrix.py b/tests/test_matrix.py index 7dbafdc..edcfe37 100644 --- a/tests/test_matrix.py +++ b/tests/test_matrix.py @@ -48,6 +48,23 @@ def test_basic(): formatted_body = "<span data-mx-spoiler>this message contains a spoiler</span>" assert(format_for_matrix(test) == formatted_body) +def test_empty(): + test = "__ ** ~~ ``" + formatted_body = "__ ** ~~ ``" + assert(format_for_matrix(test) == formatted_body) + + test = "```\n```" + formatted_body = "```<br>```" + assert(format_for_matrix(test) == formatted_body) + + test = "```python\n```" + formatted_body = "```python<br>```" + assert(format_for_matrix(test) == formatted_body) + + test = "_____" + formatted_body = "_____" + assert(format_for_matrix(test) == formatted_body) + def test_quotes(): test = ">single" formatted_body = "<blockquote>single</blockquote>" |
