aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/list.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-12 17:53:05 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-12 17:53:05 +0200
commit879fbf500d0aef45cf5811569a53510013440bcd (patch)
tree0e8c0183fa8b6b0060bef780eabc773ab30ee870 /src/construct/list.rs
parent2e3b7abaa9877b658fa4f8f2612acc617dff60bb (diff)
downloadmarkdown-rs-879fbf500d0aef45cf5811569a53510013440bcd.tar.gz
markdown-rs-879fbf500d0aef45cf5811569a53510013440bcd.tar.bz2
markdown-rs-879fbf500d0aef45cf5811569a53510013440bcd.zip
Fix to prefer thematic breaks over lists
Diffstat (limited to 'src/construct/list.rs')
-rw-r--r--src/construct/list.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/construct/list.rs b/src/construct/list.rs
index b4ae9b1..b81a5cc 100644
--- a/src/construct/list.rs
+++ b/src/construct/list.rs
@@ -3,6 +3,7 @@
use crate::constant::{LIST_ITEM_VALUE_SIZE_MAX, TAB_SIZE};
use crate::construct::{
blank_line::start as blank_line, partial_space_or_tab::space_or_tab_min_max,
+ thematic_break::start as thematic_break,
};
use crate::token::Token;
use crate::tokenizer::{Code, Event, EventType, State, StateFnResult, Tokenizer};
@@ -106,12 +107,10 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
fn before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
match code {
// Unordered.
- Code::Char('*' | '+' | '-') => {
- // To do: check if this is a thematic break?
- tokenizer.enter(Token::ListItem);
- tokenizer.enter(Token::ListItemPrefix);
- marker(tokenizer, code)
- }
+ Code::Char('*' | '+' | '-') => tokenizer.check(thematic_break, |ok| {
+ let func = if ok { nok } else { before_unordered };
+ Box::new(func)
+ })(tokenizer, code),
// Ordered.
Code::Char(char) if char.is_ascii_digit() => {
tokenizer.enter(Token::ListItem);
@@ -125,6 +124,19 @@ fn before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
}
/// To do.
+fn nok(_tokenizer: &mut Tokenizer, _code: Code) -> StateFnResult {
+ (State::Nok, None)
+}
+
+/// To do.
+fn before_unordered(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
+ // To do: check if this is a thematic break?
+ tokenizer.enter(Token::ListItem);
+ tokenizer.enter(Token::ListItemPrefix);
+ marker(tokenizer, code)
+}
+
+/// To do.
fn inside(tokenizer: &mut Tokenizer, code: Code, mut size: usize) -> StateFnResult {
size += 1;
match code {