inline: span with attributes
This commit is contained in:
parent
6bd30f1a58
commit
b937b4f71e
1 changed files with 38 additions and 1 deletions
|
@ -259,7 +259,7 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
let (d, e) = self.openers[o];
|
let (d, e) = self.openers[o];
|
||||||
let e_attr = e;
|
let e_attr = e;
|
||||||
let e_opener = e + 1;
|
let e_opener = e + 1;
|
||||||
let event = match Container::try_from(d) {
|
let mut event = match Container::try_from(d) {
|
||||||
Ok(cont) => {
|
Ok(cont) => {
|
||||||
self.events[e_opener].kind = EventKind::Enter(cont);
|
self.events[e_opener].kind = EventKind::Enter(cont);
|
||||||
Some(Event {
|
Some(Event {
|
||||||
|
@ -273,6 +273,7 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
let mut ahead = self.lexer.inner().clone();
|
let mut ahead = self.lexer.inner().clone();
|
||||||
let mut attr_len = attr::valid(&mut ahead);
|
let mut attr_len = attr::valid(&mut ahead);
|
||||||
if attr_len > 0 {
|
if attr_len > 0 {
|
||||||
|
let span_closer = self.span;
|
||||||
self.events[e_attr].span = Span::empty_at(self.span.end());
|
self.events[e_attr].span = Span::empty_at(self.span.end());
|
||||||
self.events[e_attr].kind = EventKind::Attributes;
|
self.events[e_attr].kind = EventKind::Attributes;
|
||||||
while attr_len > 0 {
|
while attr_len > 0 {
|
||||||
|
@ -281,6 +282,14 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
self.events[e_attr].span = self.span;
|
self.events[e_attr].span = self.span;
|
||||||
attr_len = attr::valid(&mut ahead);
|
attr_len = attr::valid(&mut ahead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if event.is_none() {
|
||||||
|
self.events[e_opener].kind = EventKind::Enter(Container::Span);
|
||||||
|
event = Some(Event {
|
||||||
|
kind: EventKind::Exit(Container::Span),
|
||||||
|
span: span_closer,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
event
|
event
|
||||||
} else {
|
} else {
|
||||||
|
@ -680,6 +689,34 @@ mod test {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn span_url_empty() {
|
||||||
|
test_parse!(
|
||||||
|
"before [text]() after",
|
||||||
|
(Str, "before "),
|
||||||
|
(Enter(InlineLink), ""),
|
||||||
|
(Str, "text"),
|
||||||
|
(Exit(InlineLink), ""),
|
||||||
|
(Str, " after"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn span() {
|
||||||
|
test_parse!("[abc]", (Str, "[abc]"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn span_attr() {
|
||||||
|
test_parse!(
|
||||||
|
"[abc]{.def}",
|
||||||
|
(Attributes, "{.def}"),
|
||||||
|
(Enter(Span), "["),
|
||||||
|
(Str, "abc"),
|
||||||
|
(Exit(Span), "]"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn autolink() {
|
fn autolink() {
|
||||||
test_parse!(
|
test_parse!(
|
||||||
|
|
Loading…
Reference in a new issue