From 91987c153449ea8b8ecb55cbc5968669e35454cb Mon Sep 17 00:00:00 2001 From: SavagePeanut Date: Thu, 18 Jan 2024 18:41:03 -0600 Subject: fix empty styles --- src/parser.rs | 23 ++++++++++------------- 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, 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, 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, keyword: char, start: usize, repetitions: usize, None } -fn seek_higher_order_end(chars: &Vec, keyword: char, start: usize, repetitions: usize, end: usize) -> Option { +fn seek_higher_order_end(chars: &Vec, keyword: char, start: usize, end: usize) -> Option { + 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 = "this message contains a spoiler" assert(format_for_matrix(test) == formatted_body) +def test_empty(): + test = "__ ** ~~ ``" + formatted_body = "__ ** ~~ ``" + assert(format_for_matrix(test) == formatted_body) + + test = "```\n```" + formatted_body = "```
```" + assert(format_for_matrix(test) == formatted_body) + + test = "```python\n```" + formatted_body = "```python
```" + assert(format_for_matrix(test) == formatted_body) + + test = "_____" + formatted_body = "_____" + assert(format_for_matrix(test) == formatted_body) + def test_quotes(): test = ">single" formatted_body = "
single
" -- cgit v1.2.3