aboutsummaryrefslogtreecommitdiffstats
path: root/src/content
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-15 15:46:23 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-15 15:46:23 +0200
commitb7ec5d868bf9d4688fb16dd73f8fe05b3426b86c (patch)
tree2388c44d0287007197985f564ec9df7506230367 /src/content
parent337d3b3d8fca29ff90cf79c18690e14fb7a17ae2 (diff)
downloadmarkdown-rs-b7ec5d868bf9d4688fb16dd73f8fe05b3426b86c.tar.gz
markdown-rs-b7ec5d868bf9d4688fb16dd73f8fe05b3426b86c.tar.bz2
markdown-rs-b7ec5d868bf9d4688fb16dd73f8fe05b3426b86c.zip
Add docs and refactor list
Diffstat (limited to 'src/content')
-rw-r--r--src/content/document.rs74
1 files changed, 29 insertions, 45 deletions
diff --git a/src/content/document.rs b/src/content/document.rs
index 82ccd65..704cfea 100644
--- a/src/content/document.rs
+++ b/src/content/document.rs
@@ -9,8 +9,8 @@
//! * [List][crate::construct::list]
use crate::construct::{
- block_quote::{cont as block_quote_cont, end as block_quote_end, start as block_quote},
- list::{cont as list_item_const, end as list_item_end, start as list_item},
+ block_quote::{cont as block_quote_cont, start as block_quote},
+ list::{cont as list_item_const, start as list_item},
};
use crate::content::flow::start as flow;
use crate::parser::ParseState;
@@ -296,33 +296,26 @@ fn container_new_after(
// Remove from the event stack.
// We’ll properly add exits at different points manually.
- let end = match container.kind {
- Container::BlockQuote => block_quote_end,
- Container::ListItem => list_item_end,
+ let token_type = match container.kind {
+ Container::BlockQuote => Token::BlockQuote,
+ Container::ListItem => Token::ListItem,
};
- let token_types = end();
+ let mut stack_index = tokenizer.stack.len();
+ let mut found = false;
- let mut index = 0;
- while index < token_types.len() {
- let token_type = &token_types[index];
- let mut stack_index = tokenizer.stack.len();
- let mut found = false;
-
- while stack_index > 0 {
- stack_index -= 1;
-
- if tokenizer.stack[stack_index] == *token_type {
- tokenizer.stack.remove(stack_index);
- found = true;
- break;
- }
- }
+ while stack_index > 0 {
+ stack_index -= 1;
- assert!(found, "expected to find container token to exit");
- index += 1;
+ if tokenizer.stack[stack_index] == token_type {
+ tokenizer.stack.remove(stack_index);
+ found = true;
+ break;
+ }
}
+ assert!(found, "expected to find container token to exit");
+
// If we did not continue all existing containers, and there is a new one,
// close the flow and those containers.
if info.continued != info.stack.len() {
@@ -467,30 +460,21 @@ fn exit_containers(
while !stack_close.is_empty() {
let container = stack_close.pop().unwrap();
- let end = match container.kind {
- Container::BlockQuote => block_quote_end,
- Container::ListItem => list_item_end,
+ let token_type = match container.kind {
+ Container::BlockQuote => Token::BlockQuote,
+ Container::ListItem => Token::ListItem,
};
- let token_types = end();
-
- let mut index = 0;
- while index < token_types.len() {
- let token_type = &token_types[index];
-
- exits.push(Event {
- event_type: EventType::Exit,
- token_type: token_type.clone(),
- // Note: positions are fixed later.
- point: tokenizer.point.clone(),
- index: tokenizer.index,
- previous: None,
- next: None,
- content_type: None,
- });
-
- index += 1;
- }
+ exits.push(Event {
+ event_type: EventType::Exit,
+ token_type: token_type.clone(),
+ // Note: positions are fixed later.
+ point: tokenizer.point.clone(),
+ index: tokenizer.index,
+ previous: None,
+ next: None,
+ content_type: None,
+ });
}
let index = info.inject.len() - (if *phase == Phase::Eof { 1 } else { 2 });