block: include attributes in open event span
This commit is contained in:
parent
b0f88230aa
commit
42ce9a3670
1 changed files with 14 additions and 2 deletions
16
src/lib.rs
16
src/lib.rs
|
@ -559,8 +559,9 @@ pub struct Parser<'s> {
|
||||||
/// Contents obtained by the prepass.
|
/// Contents obtained by the prepass.
|
||||||
pre_pass: PrePass<'s>,
|
pre_pass: PrePass<'s>,
|
||||||
|
|
||||||
/// Last parsed block attributes
|
/// Last parsed block attributes, and its starting offset.
|
||||||
block_attributes: Attributes<'s>,
|
block_attributes: Attributes<'s>,
|
||||||
|
block_attributes_pos: Option<usize>,
|
||||||
|
|
||||||
/// Current table row is a head row.
|
/// Current table row is a head row.
|
||||||
table_head_row: bool,
|
table_head_row: bool,
|
||||||
|
@ -785,6 +786,7 @@ impl<'s> Parser<'s> {
|
||||||
blocks: blocks.into_iter().peekable(),
|
blocks: blocks.into_iter().peekable(),
|
||||||
pre_pass,
|
pre_pass,
|
||||||
block_attributes: Attributes::new(),
|
block_attributes: Attributes::new(),
|
||||||
|
block_attributes_pos: None,
|
||||||
table_head_row: false,
|
table_head_row: false,
|
||||||
verbatim: false,
|
verbatim: false,
|
||||||
inline_parser,
|
inline_parser,
|
||||||
|
@ -896,15 +898,21 @@ impl<'s> Parser<'s> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block(&mut self) -> Option<Event<'s>> {
|
fn block(&mut self) -> Option<Event<'s>> {
|
||||||
while let Some(ev) = &mut self.blocks.next() {
|
while let Some(mut ev) = &mut self.blocks.next() {
|
||||||
let content = ev.span.of(self.src);
|
let content = ev.span.of(self.src);
|
||||||
let event = match ev.kind {
|
let event = match ev.kind {
|
||||||
block::EventKind::Atom(a) => match a {
|
block::EventKind::Atom(a) => match a {
|
||||||
block::Atom::Blankline => Event::Blankline,
|
block::Atom::Blankline => Event::Blankline,
|
||||||
block::Atom::ThematicBreak => {
|
block::Atom::ThematicBreak => {
|
||||||
|
if let Some(pos) = self.block_attributes_pos.take() {
|
||||||
|
ev.span = Span::new(pos, ev.span.end());
|
||||||
|
}
|
||||||
Event::ThematicBreak(self.block_attributes.take())
|
Event::ThematicBreak(self.block_attributes.take())
|
||||||
}
|
}
|
||||||
block::Atom::Attributes => {
|
block::Atom::Attributes => {
|
||||||
|
if self.block_attributes_pos.is_none() {
|
||||||
|
self.block_attributes_pos = Some(ev.span.start());
|
||||||
|
}
|
||||||
self.block_attributes.parse(content);
|
self.block_attributes.parse(content);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1002,9 +1010,13 @@ impl<'s> Parser<'s> {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if enter {
|
if enter {
|
||||||
|
if let Some(pos) = self.block_attributes_pos.take() {
|
||||||
|
ev.span = Span::new(pos, ev.span.end());
|
||||||
|
}
|
||||||
Event::Start(cont, self.block_attributes.take())
|
Event::Start(cont, self.block_attributes.take())
|
||||||
} else {
|
} else {
|
||||||
self.block_attributes = Attributes::new();
|
self.block_attributes = Attributes::new();
|
||||||
|
self.block_attributes_pos = None;
|
||||||
Event::End(cont)
|
Event::End(cont)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue