aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/autolink.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-01 10:17:25 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-01 10:17:25 +0200
commit82221ba13d2a4ccd119f280aaa3cea9ca2c8fdaf (patch)
tree5a9fe3ad27ab001e613d6e50c1dd67041862ce3a /src/construct/autolink.rs
parent0eeff9148e327183e532752f46421a75506dd7a6 (diff)
downloadmarkdown-rs-82221ba13d2a4ccd119f280aaa3cea9ca2c8fdaf.tar.gz
markdown-rs-82221ba13d2a4ccd119f280aaa3cea9ca2c8fdaf.tar.bz2
markdown-rs-82221ba13d2a4ccd119f280aaa3cea9ca2c8fdaf.zip
Refactor some states
Diffstat (limited to 'src/construct/autolink.rs')
-rw-r--r--src/construct/autolink.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/construct/autolink.rs b/src/construct/autolink.rs
index c0514ae..bac291e 100644
--- a/src/construct/autolink.rs
+++ b/src/construct/autolink.rs
@@ -156,6 +156,7 @@ fn open(tokenizer: &mut Tokenizer) -> State {
/// ```
fn scheme_or_email_atext(tokenizer: &mut Tokenizer) -> State {
match tokenizer.current {
+ // ASCII alphanumeric and `+`, `-`, and `.`.
Some(b'+' | b'-' | b'.' | b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z') => {
scheme_inside_or_email_atext(tokenizer, 1)
}
@@ -177,6 +178,7 @@ fn scheme_inside_or_email_atext(tokenizer: &mut Tokenizer, size: usize) -> State
tokenizer.consume();
State::Fn(Box::new(url_inside))
}
+ // ASCII alphanumeric and `+`, `-`, and `.`.
Some(b'+' | b'-' | b'.' | b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z')
if size < AUTOLINK_SCHEME_SIZE_MAX =>
{
@@ -199,8 +201,8 @@ fn url_inside(tokenizer: &mut Tokenizer) -> State {
tokenizer.exit(Token::AutolinkProtocol);
end(tokenizer)
}
- // ASCII control or space.
- None | Some(b'\0'..=0x1F | b' ' | 0x7F) => State::Nok,
+ // ASCII control, space, or `<`.
+ None | Some(b'\0'..=0x1F | b' ' | b'<' | 0x7F) => State::Nok,
Some(_) => {
tokenizer.consume();
State::Fn(Box::new(url_inside))
@@ -295,14 +297,15 @@ fn email_label(tokenizer: &mut Tokenizer, size: usize) -> State {
/// ```
fn email_value(tokenizer: &mut Tokenizer, size: usize) -> State {
match tokenizer.current {
- Some(b'-') if size < AUTOLINK_DOMAIN_SIZE_MAX => {
+ // ASCII alphanumeric or `-`.
+ Some(b'-' | b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z') if size < AUTOLINK_DOMAIN_SIZE_MAX => {
+ let func = if matches!(tokenizer.current, Some(b'-')) {
+ email_value
+ } else {
+ email_label
+ };
tokenizer.consume();
- State::Fn(Box::new(move |t| email_value(t, size + 1)))
- }
- // ASCII alphanumeric.
- Some(b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z') if size < AUTOLINK_DOMAIN_SIZE_MAX => {
- tokenizer.consume();
- State::Fn(Box::new(move |t| email_label(t, size + 1)))
+ State::Fn(Box::new(move |t| func(t, size + 1)))
}
_ => State::Nok,
}