diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/construct/attention.rs | 4 | ||||
-rw-r--r-- | src/construct/label_end.rs | 338 | ||||
-rw-r--r-- | src/construct/list.rs | 4 | ||||
-rw-r--r-- | src/construct/partial_data.rs | 4 |
4 files changed, 175 insertions, 175 deletions
diff --git a/src/construct/attention.rs b/src/construct/attention.rs index e1fa82f..86c9249 100644 --- a/src/construct/attention.rs +++ b/src/construct/attention.rs @@ -197,7 +197,7 @@ fn inside(tokenizer: &mut Tokenizer, code: Code, marker: MarkerKind) -> StateFnR } _ => { tokenizer.exit(Token::AttentionSequence); - tokenizer.register_resolver("attention".to_string(), Box::new(resolve)); + tokenizer.register_resolver("attention".to_string(), Box::new(resolve_attention)); (State::Ok, Some(vec![code])) } } @@ -205,7 +205,7 @@ fn inside(tokenizer: &mut Tokenizer, code: Code, marker: MarkerKind) -> StateFnR /// Resolve attention sequences. #[allow(clippy::too_many_lines)] -fn resolve(tokenizer: &mut Tokenizer) -> Vec<Event> { +fn resolve_attention(tokenizer: &mut Tokenizer) -> Vec<Event> { let codes = &tokenizer.parse_state.codes; let mut edit_map = EditMap::new(); let mut start = 0; diff --git a/src/construct/label_end.rs b/src/construct/label_end.rs index 2db68b5..e232cbe 100644 --- a/src/construct/label_end.rs +++ b/src/construct/label_end.rs @@ -172,175 +172,6 @@ struct Info { media: Media, } -/// Resolve media. -/// -/// This turns correct label start (image, link) and label end into links and -/// images, or turns them back into data. -#[allow(clippy::too_many_lines)] -pub fn resolve_media(tokenizer: &mut Tokenizer) -> Vec<Event> { - let mut left: Vec<LabelStart> = tokenizer.label_start_list_loose.drain(..).collect(); - let mut left_2: Vec<LabelStart> = tokenizer.label_start_stack.drain(..).collect(); - let media: Vec<Media> = tokenizer.media_list.drain(..).collect(); - left.append(&mut left_2); - - let mut edit_map = EditMap::new(); - let events = &tokenizer.events; - - // Remove loose label starts. - let mut index = 0; - while index < left.len() { - let label_start = &left[index]; - let data_enter_index = label_start.start.0; - let data_exit_index = label_start.start.1; - - edit_map.add( - data_enter_index, - data_exit_index - data_enter_index + 1, - vec![ - Event { - event_type: EventType::Enter, - token_type: Token::Data, - point: events[data_enter_index].point.clone(), - index: events[data_enter_index].index, - previous: None, - next: None, - content_type: None, - }, - Event { - event_type: EventType::Exit, - token_type: Token::Data, - point: events[data_exit_index].point.clone(), - index: events[data_exit_index].index, - previous: None, - next: None, - content_type: None, - }, - ], - ); - - index += 1; - } - - // Add grouping events. - let mut index = 0; - while index < media.len() { - let media = &media[index]; - // LabelLink:Enter or LabelImage:Enter. - let group_enter_index = media.start.0; - let group_enter_event = &events[group_enter_index]; - // LabelLink:Exit or LabelImage:Exit. - let text_enter_index = media.start.0 - + (if group_enter_event.token_type == Token::LabelLink { - 4 - } else { - 6 - }); - // LabelEnd:Enter. - let text_exit_index = media.end.0; - // LabelEnd:Exit. - let label_exit_index = media.end.0 + 3; - // Resource:Exit, etc. - let group_end_index = media.end.1; - - // Insert a group enter and label enter. - edit_map.add( - group_enter_index, - 0, - vec![ - Event { - event_type: EventType::Enter, - token_type: if group_enter_event.token_type == Token::LabelLink { - Token::Link - } else { - Token::Image - }, - point: group_enter_event.point.clone(), - index: group_enter_event.index, - previous: None, - next: None, - content_type: None, - }, - Event { - event_type: EventType::Enter, - token_type: Token::Label, - point: group_enter_event.point.clone(), - index: group_enter_event.index, - previous: None, - next: None, - content_type: None, - }, - ], - ); - - // Empty events not allowed. - if text_enter_index != text_exit_index { - // Insert a text enter. - edit_map.add( - text_enter_index, - 0, - vec![Event { - event_type: EventType::Enter, - token_type: Token::LabelText, - point: events[text_enter_index].point.clone(), - index: events[text_enter_index].index, - previous: None, - next: None, - content_type: None, - }], - ); - - // Insert a text exit. - edit_map.add( - text_exit_index, - 0, - vec![Event { - event_type: EventType::Exit, - token_type: Token::LabelText, - point: events[text_exit_index].point.clone(), - index: events[text_exit_index].index, - previous: None, - next: None, - content_type: None, - }], - ); - } - - // Insert a label exit. - edit_map.add( - label_exit_index + 1, - 0, - vec![Event { - event_type: EventType::Exit, - token_type: Token::Label, - point: events[label_exit_index].point.clone(), - index: events[label_exit_index].index, - previous: None, - next: None, - content_type: None, - }], - ); - - // Insert a group exit. - edit_map.add( - group_end_index + 1, - 0, - vec![Event { - event_type: EventType::Exit, - token_type: Token::Link, - point: events[group_end_index].point.clone(), - index: events[group_end_index].index, - previous: None, - next: None, - content_type: None, - }], - ); - - index += 1; - } - - edit_map.consume(&mut tokenizer.events) -} - /// Start of label end. /// /// ```markdown @@ -778,3 +609,172 @@ fn collapsed_reference_open(tokenizer: &mut Tokenizer, code: Code) -> StateFnRes _ => (State::Nok, None), } } + +/// Resolve media. +/// +/// This turns correct label start (image, link) and label end into links and +/// images, or turns them back into data. +#[allow(clippy::too_many_lines)] +pub fn resolve_media(tokenizer: &mut Tokenizer) -> Vec<Event> { + let mut left: Vec<LabelStart> = tokenizer.label_start_list_loose.drain(..).collect(); + let mut left_2: Vec<LabelStart> = tokenizer.label_start_stack.drain(..).collect(); + let media: Vec<Media> = tokenizer.media_list.drain(..).collect(); + left.append(&mut left_2); + + let mut edit_map = EditMap::new(); + let events = &tokenizer.events; + + // Remove loose label starts. + let mut index = 0; + while index < left.len() { + let label_start = &left[index]; + let data_enter_index = label_start.start.0; + let data_exit_index = label_start.start.1; + + edit_map.add( + data_enter_index, + data_exit_index - data_enter_index + 1, + vec![ + Event { + event_type: EventType::Enter, + token_type: Token::Data, + point: events[data_enter_index].point.clone(), + index: events[data_enter_index].index, + previous: None, + next: None, + content_type: None, + }, + Event { + event_type: EventType::Exit, + token_type: Token::Data, + point: events[data_exit_index].point.clone(), + index: events[data_exit_index].index, + previous: None, + next: None, + content_type: None, + }, + ], + ); + + index += 1; + } + + // Add grouping events. + let mut index = 0; + while index < media.len() { + let media = &media[index]; + // LabelLink:Enter or LabelImage:Enter. + let group_enter_index = media.start.0; + let group_enter_event = &events[group_enter_index]; + // LabelLink:Exit or LabelImage:Exit. + let text_enter_index = media.start.0 + + (if group_enter_event.token_type == Token::LabelLink { + 4 + } else { + 6 + }); + // LabelEnd:Enter. + let text_exit_index = media.end.0; + // LabelEnd:Exit. + let label_exit_index = media.end.0 + 3; + // Resource:Exit, etc. + let group_end_index = media.end.1; + + // Insert a group enter and label enter. + edit_map.add( + group_enter_index, + 0, + vec![ + Event { + event_type: EventType::Enter, + token_type: if group_enter_event.token_type == Token::LabelLink { + Token::Link + } else { + Token::Image + }, + point: group_enter_event.point.clone(), + index: group_enter_event.index, + previous: None, + next: None, + content_type: None, + }, + Event { + event_type: EventType::Enter, + token_type: Token::Label, + point: group_enter_event.point.clone(), + index: group_enter_event.index, + previous: None, + next: None, + content_type: None, + }, + ], + ); + + // Empty events not allowed. + if text_enter_index != text_exit_index { + // Insert a text enter. + edit_map.add( + text_enter_index, + 0, + vec![Event { + event_type: EventType::Enter, + token_type: Token::LabelText, + point: events[text_enter_index].point.clone(), + index: events[text_enter_index].index, + previous: None, + next: None, + content_type: None, + }], + ); + + // Insert a text exit. + edit_map.add( + text_exit_index, + 0, + vec![Event { + event_type: EventType::Exit, + token_type: Token::LabelText, + point: events[text_exit_index].point.clone(), + index: events[text_exit_index].index, + previous: None, + next: None, + content_type: None, + }], + ); + } + + // Insert a label exit. + edit_map.add( + label_exit_index + 1, + 0, + vec![Event { + event_type: EventType::Exit, + token_type: Token::Label, + point: events[label_exit_index].point.clone(), + index: events[label_exit_index].index, + previous: None, + next: None, + content_type: None, + }], + ); + + // Insert a group exit. + edit_map.add( + group_end_index + 1, + 0, + vec![Event { + event_type: EventType::Exit, + token_type: Token::Link, + point: events[group_end_index].point.clone(), + index: events[group_end_index].index, + previous: None, + next: None, + content_type: None, + }], + ); + + index += 1; + } + + edit_map.consume(&mut tokenizer.events) +} diff --git a/src/construct/list.rs b/src/construct/list.rs index c2007e6..fce8f00 100644 --- a/src/construct/list.rs +++ b/src/construct/list.rs @@ -315,7 +315,7 @@ fn after(tokenizer: &mut Tokenizer, code: Code, blank: bool) -> StateFnResult { container.size = prefix; tokenizer.exit(Token::ListItemPrefix); - tokenizer.register_resolver_before("list_item".to_string(), Box::new(resolve)); + tokenizer.register_resolver_before("list_item".to_string(), Box::new(resolve_list_item)); (State::Ok, Some(vec![code])) } } @@ -381,7 +381,7 @@ fn nok(_tokenizer: &mut Tokenizer, _code: Code) -> StateFnResult { } /// Find adjacent list items with the same marker. -pub fn resolve(tokenizer: &mut Tokenizer) -> Vec<Event> { +pub fn resolve_list_item(tokenizer: &mut Tokenizer) -> Vec<Event> { let mut edit_map = EditMap::new(); let mut index = 0; let mut balance = 0; diff --git a/src/construct/partial_data.rs b/src/construct/partial_data.rs index b4dfda0..3bc8c1c 100644 --- a/src/construct/partial_data.rs +++ b/src/construct/partial_data.rs @@ -42,7 +42,7 @@ fn at_break(tokenizer: &mut Tokenizer, code: Code, stop: Vec<Code>) -> StateFnRe (State::Fn(Box::new(|t, c| at_break(t, c, stop))), None) } _ if stop.contains(&code) => { - tokenizer.register_resolver("data".to_string(), Box::new(resolve)); + tokenizer.register_resolver("data".to_string(), Box::new(resolve_data)); (State::Ok, Some(vec![code])) } _ => { @@ -75,7 +75,7 @@ fn data(tokenizer: &mut Tokenizer, code: Code, stop: Vec<Code>) -> StateFnResult } /// Merge adjacent data events. -pub fn resolve(tokenizer: &mut Tokenizer) -> Vec<Event> { +pub fn resolve_data(tokenizer: &mut Tokenizer) -> Vec<Event> { let mut edit_map = EditMap::new(); let len = tokenizer.events.len(); let mut index = 0; |