block: add MeteredBlock as intermediate struct

This commit is contained in:
Noah Hellman 2023-01-29 09:24:46 +01:00
parent 1c77b035b2
commit dcb3b787a2
3 changed files with 460 additions and 291 deletions

File diff suppressed because it is too large Load diff

View file

@ -589,23 +589,27 @@ impl<'s> Parser<'s> {
attributes = Attributes::new(); attributes = Attributes::new();
continue; continue;
} }
block::Container::DescriptionList => Container::DescriptionList,
block::Container::List { ty, tight } => { block::Container::List { ty, tight } => {
let kind = match ty { if matches!(ty, block::ListType::Description) {
block::ListType::Unordered(..) => ListKind::Unordered, Container::DescriptionList
block::ListType::Ordered(numbering, style) => { } else {
let marker = ev.span.of(self.src); let kind = match ty {
let start = block::ListType::Unordered(..) => ListKind::Unordered,
numbering.parse_number(style.number(marker)).max(1); block::ListType::Task => ListKind::Task,
ListKind::Ordered { block::ListType::Ordered(numbering, style) => {
numbering, let start = numbering
style, .parse_number(style.number(content))
start, .max(1);
ListKind::Ordered {
numbering,
style,
start,
}
} }
} block::ListType::Description => unreachable!(),
block::ListType::Task => ListKind::Task, };
}; Container::List { kind, tight }
Container::List { kind, tight } }
} }
block::Container::ListItem(ty) => { block::Container::ListItem(ty) => {
if matches!(ty, block::ListType::Task) { if matches!(ty, block::ListType::Task) {

View file

@ -89,10 +89,6 @@ impl Span {
&s[self.start()..self.end()] &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 { pub fn trim_start(self, s: &str) -> Self {
Self::from_slice(s, self.of(s).trim_start()) Self::from_slice(s, self.of(s).trim_start())
} }
@ -104,6 +100,10 @@ impl Span {
pub fn trim(self, s: &str) -> Self { pub fn trim(self, s: &str) -> Self {
Self::from_slice(s, self.of(s).trim_start().trim_end()) 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> { pub trait DiscontinuousString<'s> {