block: add MeteredBlock as intermediate struct
This commit is contained in:
parent
1c77b035b2
commit
dcb3b787a2
3 changed files with 460 additions and 291 deletions
709
src/block.rs
709
src/block.rs
File diff suppressed because it is too large
Load diff
34
src/lib.rs
34
src/lib.rs
|
@ -589,23 +589,27 @@ impl<'s> Parser<'s> {
|
|||
attributes = Attributes::new();
|
||||
continue;
|
||||
}
|
||||
block::Container::DescriptionList => Container::DescriptionList,
|
||||
block::Container::List { ty, tight } => {
|
||||
let kind = match ty {
|
||||
block::ListType::Unordered(..) => ListKind::Unordered,
|
||||
block::ListType::Ordered(numbering, style) => {
|
||||
let marker = ev.span.of(self.src);
|
||||
let start =
|
||||
numbering.parse_number(style.number(marker)).max(1);
|
||||
ListKind::Ordered {
|
||||
numbering,
|
||||
style,
|
||||
start,
|
||||
if matches!(ty, block::ListType::Description) {
|
||||
Container::DescriptionList
|
||||
} else {
|
||||
let kind = match ty {
|
||||
block::ListType::Unordered(..) => ListKind::Unordered,
|
||||
block::ListType::Task => ListKind::Task,
|
||||
block::ListType::Ordered(numbering, style) => {
|
||||
let start = numbering
|
||||
.parse_number(style.number(content))
|
||||
.max(1);
|
||||
ListKind::Ordered {
|
||||
numbering,
|
||||
style,
|
||||
start,
|
||||
}
|
||||
}
|
||||
}
|
||||
block::ListType::Task => ListKind::Task,
|
||||
};
|
||||
Container::List { kind, tight }
|
||||
block::ListType::Description => unreachable!(),
|
||||
};
|
||||
Container::List { kind, tight }
|
||||
}
|
||||
}
|
||||
block::Container::ListItem(ty) => {
|
||||
if matches!(ty, block::ListType::Task) {
|
||||
|
|
|
@ -89,10 +89,6 @@ impl Span {
|
|||
&s[self.start()..self.end()]
|
||||
}
|
||||
|
||||
pub fn from_slice(s: &str, slice: &str) -> Self {
|
||||
Self::by_len(slice.as_ptr() as usize - s.as_ptr() as usize, slice.len())
|
||||
}
|
||||
|
||||
pub fn trim_start(self, s: &str) -> Self {
|
||||
Self::from_slice(s, self.of(s).trim_start())
|
||||
}
|
||||
|
@ -104,6 +100,10 @@ impl Span {
|
|||
pub fn trim(self, s: &str) -> Self {
|
||||
Self::from_slice(s, self.of(s).trim_start().trim_end())
|
||||
}
|
||||
|
||||
fn from_slice(s: &str, slice: &str) -> Self {
|
||||
Self::by_len(slice.as_ptr() as usize - s.as_ptr() as usize, slice.len())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait DiscontinuousString<'s> {
|
||||
|
|
Loading…
Reference in a new issue