aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/autolink.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-10 10:54:43 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-10 10:54:43 +0200
commit3a90a49518bbc53876d3f46d8763b2fe0f03d789 (patch)
treeeecaaf9586cf8632b3b6fe22794dae1f492849f5 /src/construct/autolink.rs
parent8162222295d71ea7fd9270c7b3b9497b91db3f1f (diff)
downloadmarkdown-rs-3a90a49518bbc53876d3f46d8763b2fe0f03d789.tar.gz
markdown-rs-3a90a49518bbc53876d3f46d8763b2fe0f03d789.tar.bz2
markdown-rs-3a90a49518bbc53876d3f46d8763b2fe0f03d789.zip
Add `State::Retry`
Diffstat (limited to '')
-rw-r--r--src/construct/autolink.rs47
1 files changed, 18 insertions, 29 deletions
diff --git a/src/construct/autolink.rs b/src/construct/autolink.rs
index f1b92d9..eef3840 100644
--- a/src/construct/autolink.rs
+++ b/src/construct/autolink.rs
@@ -142,7 +142,7 @@ pub fn open(tokenizer: &mut Tokenizer) -> State {
tokenizer.consume();
State::Next(StateName::AutolinkSchemeOrEmailAtext)
}
- _ => email_atext(tokenizer),
+ _ => State::Retry(StateName::AutolinkEmailAtext),
}
}
@@ -160,9 +160,9 @@ pub fn scheme_or_email_atext(tokenizer: &mut Tokenizer) -> State {
Some(b'+' | b'-' | b'.' | b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z') => {
// Count the previous alphabetical from `open` too.
tokenizer.tokenize_state.size = 1;
- scheme_inside_or_email_atext(tokenizer)
+ State::Retry(StateName::AutolinkSchemeInsideOrEmailAtext)
}
- _ => email_atext(tokenizer),
+ _ => State::Retry(StateName::AutolinkEmailAtext),
}
}
@@ -191,7 +191,7 @@ pub fn scheme_inside_or_email_atext(tokenizer: &mut Tokenizer) -> State {
}
_ => {
tokenizer.tokenize_state.size = 0;
- email_atext(tokenizer)
+ State::Retry(StateName::AutolinkEmailAtext)
}
}
}
@@ -206,7 +206,11 @@ pub fn url_inside(tokenizer: &mut Tokenizer) -> State {
match tokenizer.current {
Some(b'>') => {
tokenizer.exit(Token::AutolinkProtocol);
- end(tokenizer)
+ tokenizer.enter(Token::AutolinkMarker);
+ tokenizer.consume();
+ tokenizer.exit(Token::AutolinkMarker);
+ tokenizer.exit(Token::Autolink);
+ State::Ok
}
// ASCII control, space, or `<`.
None | Some(b'\0'..=0x1F | b' ' | b'<' | 0x7F) => State::Nok,
@@ -265,7 +269,9 @@ pub fn email_atext(tokenizer: &mut Tokenizer) -> State {
pub fn email_at_sign_or_dot(tokenizer: &mut Tokenizer) -> State {
match tokenizer.current {
// ASCII alphanumeric.
- Some(b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z') => email_value(tokenizer),
+ Some(b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z') => {
+ State::Retry(StateName::AutolinkEmailValue)
+ }
_ => State::Nok,
}
}
@@ -290,9 +296,13 @@ pub fn email_label(tokenizer: &mut Tokenizer) -> State {
// Change the token type.
tokenizer.events[index - 1].token_type = Token::AutolinkEmail;
tokenizer.events[index].token_type = Token::AutolinkEmail;
- end(tokenizer)
+ tokenizer.enter(Token::AutolinkMarker);
+ tokenizer.consume();
+ tokenizer.exit(Token::AutolinkMarker);
+ tokenizer.exit(Token::Autolink);
+ State::Ok
}
- _ => email_value(tokenizer),
+ _ => State::Retry(StateName::AutolinkEmailValue),
}
}
@@ -325,24 +335,3 @@ pub fn email_value(tokenizer: &mut Tokenizer) -> State {
}
}
}
-
-/// At the `>`.
-///
-/// ```markdown
-/// > | a<https://example.com>b
-/// ^
-/// > | a<user@example.com>b
-/// ^
-/// ```
-pub fn end(tokenizer: &mut Tokenizer) -> State {
- match tokenizer.current {
- Some(b'>') => {
- tokenizer.enter(Token::AutolinkMarker);
- tokenizer.consume();
- tokenizer.exit(Token::AutolinkMarker);
- tokenizer.exit(Token::Autolink);
- State::Ok
- }
- _ => unreachable!("expected `>`"),
- }
-}