inline: mv autolink url from span to event field
This commit is contained in:
		
					parent
					
						
							
								657b47df12
							
						
					
				
			
			
				commit
				
					
						0a144574f4
					
				
			
		
					 2 changed files with 17 additions and 20 deletions
				
			
		| 
						 | 
					@ -36,17 +36,14 @@ pub enum Container<'s> {
 | 
				
			||||||
    Strong,
 | 
					    Strong,
 | 
				
			||||||
    Mark,
 | 
					    Mark,
 | 
				
			||||||
    Verbatim,
 | 
					    Verbatim,
 | 
				
			||||||
    RawFormat {
 | 
					    RawFormat { format: &'s str },
 | 
				
			||||||
        format: &'s str,
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    InlineMath,
 | 
					    InlineMath,
 | 
				
			||||||
    DisplayMath,
 | 
					    DisplayMath,
 | 
				
			||||||
    ReferenceLink(CowStrIndex),
 | 
					    ReferenceLink(CowStrIndex),
 | 
				
			||||||
    ReferenceImage(CowStrIndex),
 | 
					    ReferenceImage(CowStrIndex),
 | 
				
			||||||
    InlineLink(CowStrIndex),
 | 
					    InlineLink(CowStrIndex),
 | 
				
			||||||
    InlineImage(CowStrIndex),
 | 
					    InlineImage(CowStrIndex),
 | 
				
			||||||
    /// Open delimiter span is URL, closing is '>'.
 | 
					    Autolink(&'s str),
 | 
				
			||||||
    Autolink,
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type CowStrIndex = u32;
 | 
					type CowStrIndex = u32;
 | 
				
			||||||
| 
						 | 
					@ -577,12 +574,13 @@ impl<'s> Parser<'s> {
 | 
				
			||||||
                .sum();
 | 
					                .sum();
 | 
				
			||||||
            if end && is_url {
 | 
					            if end && is_url {
 | 
				
			||||||
                self.input.lexer = lex::Lexer::new(ahead.as_str());
 | 
					                self.input.lexer = lex::Lexer::new(ahead.as_str());
 | 
				
			||||||
                self.input.span = self.input.span.after(len);
 | 
					                let span_url = self.input.span.after(len);
 | 
				
			||||||
                self.push(EventKind::Enter(Autolink));
 | 
					                let url = span_url.of(self.input.src);
 | 
				
			||||||
 | 
					                self.push(EventKind::Enter(Autolink(url)));
 | 
				
			||||||
 | 
					                self.input.span = span_url;
 | 
				
			||||||
                self.push(EventKind::Str);
 | 
					                self.push(EventKind::Str);
 | 
				
			||||||
                self.push(EventKind::Exit(Autolink));
 | 
					 | 
				
			||||||
                self.input.span = self.input.span.after(1);
 | 
					                self.input.span = self.input.span.after(1);
 | 
				
			||||||
                return Some(Continue);
 | 
					                return self.push(EventKind::Exit(Autolink(url)));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        None
 | 
					        None
 | 
				
			||||||
| 
						 | 
					@ -1563,24 +1561,24 @@ mod test {
 | 
				
			||||||
    fn autolink() {
 | 
					    fn autolink() {
 | 
				
			||||||
        test_parse!(
 | 
					        test_parse!(
 | 
				
			||||||
            "<https://example.com>",
 | 
					            "<https://example.com>",
 | 
				
			||||||
            (Enter(Autolink), "https://example.com"),
 | 
					            (Enter(Autolink("https://example.com",)), "<"),
 | 
				
			||||||
            (Str, "https://example.com"),
 | 
					            (Str, "https://example.com"),
 | 
				
			||||||
            (Exit(Autolink), "https://example.com")
 | 
					            (Exit(Autolink("https://example.com",)), ">")
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        test_parse!(
 | 
					        test_parse!(
 | 
				
			||||||
            "<a@b.c>",
 | 
					            "<a@b.c>",
 | 
				
			||||||
            (Enter(Autolink), "a@b.c"),
 | 
					            (Enter(Autolink("a@b.c")), "<"),
 | 
				
			||||||
            (Str, "a@b.c"),
 | 
					            (Str, "a@b.c"),
 | 
				
			||||||
            (Exit(Autolink), "a@b.c"),
 | 
					            (Exit(Autolink("a@b.c")), ">"),
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        test_parse!(
 | 
					        test_parse!(
 | 
				
			||||||
            "<http://a.b><http://c.d>",
 | 
					            "<http://a.b><http://c.d>",
 | 
				
			||||||
            (Enter(Autolink), "http://a.b"),
 | 
					            (Enter(Autolink("http://a.b")), "<"),
 | 
				
			||||||
            (Str, "http://a.b"),
 | 
					            (Str, "http://a.b"),
 | 
				
			||||||
            (Exit(Autolink), "http://a.b"),
 | 
					            (Exit(Autolink("http://a.b")), ">"),
 | 
				
			||||||
            (Enter(Autolink), "http://c.d"),
 | 
					            (Enter(Autolink("http://c.d")), "<"),
 | 
				
			||||||
            (Str, "http://c.d"),
 | 
					            (Str, "http://c.d"),
 | 
				
			||||||
            (Exit(Autolink), "http://c.d"),
 | 
					            (Exit(Autolink("http://c.d")), ">"),
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        test_parse!("<not-a-url>", (Str, "<not-a-url>"));
 | 
					        test_parse!("<not-a-url>", (Str, "<not-a-url>"));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -820,14 +820,13 @@ impl<'s> Parser<'s> {
 | 
				
			||||||
                                Container::Image(url_or_tag, ty)
 | 
					                                Container::Image(url_or_tag, ty)
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        inline::Container::Autolink => {
 | 
					                        inline::Container::Autolink(url) => {
 | 
				
			||||||
                            let url: CowStr = inline.span.of(self.src).into();
 | 
					 | 
				
			||||||
                            let ty = if url.contains('@') {
 | 
					                            let ty = if url.contains('@') {
 | 
				
			||||||
                                LinkType::Email
 | 
					                                LinkType::Email
 | 
				
			||||||
                            } else {
 | 
					                            } else {
 | 
				
			||||||
                                LinkType::AutoLink
 | 
					                                LinkType::AutoLink
 | 
				
			||||||
                            };
 | 
					                            };
 | 
				
			||||||
                            Container::Link(url, ty)
 | 
					                            Container::Link(url.into(), ty)
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    };
 | 
					                    };
 | 
				
			||||||
                    if enter {
 | 
					                    if enter {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue