diff options
| -rw-r--r-- | src/lib.rs | 31 | ||||
| -rw-r--r-- | tests/test_style_parser.py | 4 |
2 files changed, 33 insertions, 2 deletions
@@ -154,6 +154,37 @@ fn seek_end(chars: &Vec<char>, keyword: char, start: usize, end: usize) -> Optio && !chars[i - 1].is_whitespace() && !preceeded_by_backslash(chars, i, start) { + match seek_higher_order_end(chars, c, i + 1, end) { + Some(higher_order_index) => { + return Some(higher_order_index); + } + None => { + return Some(i); + } + } + } + } + None +} + +fn seek_higher_order_end(chars: &Vec<char>, keyword: char, start: usize, end: usize) -> Option<usize> { + 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) + && !preceeded_by_backslash(chars, i, start) + { + return None; // "*bold* *<--- beginning of new bold>*" + } + if c == keyword + && !chars[i - 1].is_whitespace() + && followed_by_whitespace(chars, i, end) + && !preceeded_by_backslash(chars, i, start) + { return Some(i); } } diff --git a/tests/test_style_parser.py b/tests/test_style_parser.py index f78f866..671af64 100644 --- a/tests/test_style_parser.py +++ b/tests/test_style_parser.py @@ -34,8 +34,9 @@ def test_nested(): assert(format_body("`*~_code span_~*`", MATRIX_FORMATS) == "<code>*~_code span_~*</code>") assert(format_body("*_~`code span`~_*", MATRIX_FORMATS) == "<strong><em><strike><code>code span</code></strike></em></strong>") assert(format_body(">*_~`code span`~_*", MATRIX_FORMATS) == "<blockquote><strong><em><strike><code>code span</code></strike></em></strong></blockquote>") - assert(format_body("*bold*not bold*", MATRIX_FORMATS) == "<strong>bold</strong>not bold*") + assert(format_body("*bold star >*< star bold*", MATRIX_FORMATS) == "<strong>bold star >*< star bold</strong>") assert(format_body("*_bold*_", MATRIX_FORMATS) == "<strong>_bold</strong>_") + assert(format_body("__underlined__", MATRIX_FORMATS) == "<em><em>underlined</em></em>") def test_no_changes(): assert(format_body("", MATRIX_FORMATS) == "") @@ -45,7 +46,6 @@ def test_no_changes(): assert(format_body(" > no quote", MATRIX_FORMATS) == " > no quote") assert(format_body("_not underlined", MATRIX_FORMATS) == "_not underlined") assert(format_body("|not a spoiler|", MATRIX_FORMATS) == "|not a spoiler|") - assert(format_body("__not underlined__", MATRIX_FORMATS) == "__not underlined__") assert(format_body("`no code\nblock here`", MATRIX_FORMATS) == "`no code\nblock here`") def test_assorted(): |
