aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-11 16:24:56 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-11 16:24:56 +0200
commita4dc19af6e82757af87c6658d7b1771a9694b83d (patch)
tree3c0050f0a46ffc3b0ecb54516e4c7a5447efeed4 /src
parent3048b7aca0690691d25cb8409d543b2377e065e1 (diff)
downloadmarkdown-rs-a4dc19af6e82757af87c6658d7b1771a9694b83d.tar.gz
markdown-rs-a4dc19af6e82757af87c6658d7b1771a9694b83d.tar.bz2
markdown-rs-a4dc19af6e82757af87c6658d7b1771a9694b83d.zip
Remove unneeded `balance` info on label starts
Diffstat (limited to '')
-rw-r--r--src/construct/label_end.rs51
-rw-r--r--src/construct/label_start_image.rs1
-rw-r--r--src/construct/label_start_link.rs1
-rw-r--r--src/tokenizer.rs41
4 files changed, 30 insertions, 64 deletions
diff --git a/src/construct/label_end.rs b/src/construct/label_end.rs
index 26dcf6b..bfded05 100644
--- a/src/construct/label_end.rs
+++ b/src/construct/label_end.rs
@@ -171,27 +171,10 @@ use crate::util::{
/// ```
pub fn start(tokenizer: &mut Tokenizer) -> State {
if Some(b']') == tokenizer.current && tokenizer.parse_state.constructs.label_end {
- let mut label_start_index = None;
- let mut index = tokenizer.tokenize_state.label_start_stack.len();
-
- while index > 0 {
- index -= 1;
-
- if !tokenizer.tokenize_state.label_start_stack[index].balanced {
- label_start_index = Some(index);
- break;
- }
- }
-
// If there is an okay opening:
- if let Some(label_start_index) = label_start_index {
- let label_start = tokenizer
- .tokenize_state
- .label_start_stack
- .get_mut(label_start_index)
- .unwrap();
-
- tokenizer.tokenize_state.start = label_start_index;
+ if !tokenizer.tokenize_state.label_start_stack.is_empty() {
+ let label_start = tokenizer.tokenize_state.label_start_stack.last().unwrap();
+
tokenizer.tokenize_state.end = tokenizer.events.len();
// Mark as balanced if the info is inactive.
@@ -224,7 +207,7 @@ pub fn start(tokenizer: &mut Tokenizer) -> State {
/// ^
/// ```
pub fn after(tokenizer: &mut Tokenizer) -> State {
- let start = &tokenizer.tokenize_state.label_start_stack[tokenizer.tokenize_state.start];
+ let start = tokenizer.tokenize_state.label_start_stack.last().unwrap();
let defined = tokenizer
.parse_state
.definitions
@@ -299,18 +282,8 @@ pub fn reference_not_full(tokenizer: &mut Tokenizer) -> State {
/// ^
/// ```
pub fn ok(tokenizer: &mut Tokenizer) -> State {
- let label_start_index = tokenizer.tokenize_state.start;
- // Remove this one and everything after it.
- let mut left = tokenizer
- .tokenize_state
- .label_start_stack
- .split_off(label_start_index);
- // Remove this one from `left`, as we’ll move it to `media_list`.
- let label_start = left.remove(0);
- tokenizer
- .tokenize_state
- .label_start_list_loose
- .append(&mut left);
+ // Remove the start.
+ let label_start = tokenizer.tokenize_state.label_start_stack.pop().unwrap();
let is_link = tokenizer.events[label_start.start.0].name == Name::LabelLink;
@@ -329,7 +302,6 @@ pub fn ok(tokenizer: &mut Tokenizer) -> State {
start: label_start.start,
end: (tokenizer.tokenize_state.end, tokenizer.events.len() - 1),
});
- tokenizer.tokenize_state.start = 0;
tokenizer.tokenize_state.end = 0;
tokenizer.register_resolver_before(ResolveName::Label);
State::Ok
@@ -348,13 +320,10 @@ pub fn ok(tokenizer: &mut Tokenizer) -> State {
/// ^
/// ```
pub fn nok(tokenizer: &mut Tokenizer) -> State {
- tokenizer
- .tokenize_state
- .label_start_stack
- .get_mut(tokenizer.tokenize_state.start)
- .unwrap()
- .balanced = true;
- tokenizer.tokenize_state.start = 0;
+ let start = tokenizer.tokenize_state.label_start_stack.pop().unwrap();
+
+ tokenizer.tokenize_state.label_start_list_loose.push(start);
+
tokenizer.tokenize_state.end = 0;
State::Nok
}
diff --git a/src/construct/label_start_image.rs b/src/construct/label_start_image.rs
index c9f76b0..b8c8858 100644
--- a/src/construct/label_start_image.rs
+++ b/src/construct/label_start_image.rs
@@ -67,7 +67,6 @@ pub fn open(tokenizer: &mut Tokenizer) -> State {
tokenizer.exit(Name::LabelImage);
tokenizer.tokenize_state.label_start_stack.push(LabelStart {
start: (tokenizer.events.len() - 6, tokenizer.events.len() - 1),
- balanced: false,
inactive: false,
});
tokenizer.register_resolver_before(ResolveName::Label);
diff --git a/src/construct/label_start_link.rs b/src/construct/label_start_link.rs
index 6b022c5..7288d5d 100644
--- a/src/construct/label_start_link.rs
+++ b/src/construct/label_start_link.rs
@@ -49,7 +49,6 @@ pub fn start(tokenizer: &mut Tokenizer) -> State {
tokenizer.exit(Name::LabelLink);
tokenizer.tokenize_state.label_start_stack.push(LabelStart {
start: (start, tokenizer.events.len() - 1),
- balanced: false,
inactive: false,
});
tokenizer.register_resolver_before(ResolveName::Label);
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index b2d0751..8ff19c3 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -18,22 +18,6 @@ use crate::resolve::{call as call_resolve, Name as ResolveName};
use crate::state::{call, Name as StateName, State};
use crate::util::edit_map::EditMap;
-/// Media we found.
-#[derive(Debug)]
-pub struct Media {
- /// Indices of where the media’s label start starts and ends in `events`.
- pub start: (usize, usize),
- /// Indices of where the media’s label end starts and ends in `events`.
- pub end: (usize, usize),
-}
-
-/// Supported containers.
-#[derive(Debug, PartialEq)]
-pub enum Container {
- BlockQuote,
- ListItem,
-}
-
/// Info used to tokenize the current container.
///
/// This info is shared between the initial construct and its continuation.
@@ -61,17 +45,32 @@ enum ByteAction {
Ignore,
}
+/// Supported containers.
+#[derive(Debug, PartialEq)]
+pub enum Container {
+ BlockQuote,
+ ListItem,
+}
+
/// Loose label starts we found.
#[derive(Debug)]
pub struct LabelStart {
/// Indices of where the label starts and ends in `events`.
pub start: (usize, usize),
- /// A boolean used internally to figure out if a label start link can’t be
- /// used (because links in links are incorrect).
+ /// A boolean used internally to figure out if a (link) label start link
+ /// can’t be used anymore (because it would contain another link).
+ /// That link start is still looking for a balanced closing bracket though,
+ /// so we can’t remove it just yet.
pub inactive: bool,
- /// A boolean used internally to figure out if a label is balanced: they’re
- /// not media, it’s just balanced braces.
- pub balanced: bool,
+}
+
+/// Media we found.
+#[derive(Debug)]
+pub struct Media {
+ /// Indices of where the media’s label start starts and ends in `events`.
+ pub start: (usize, usize),
+ /// Indices of where the media’s label end starts and ends in `events`.
+ pub end: (usize, usize),
}
/// Different kinds of attempts.