fix(npf): check if vectors has element before accessing them

This commit is contained in:
Gustavo "Guz" L. de Mello
2024-05-02 14:01:08 -03:00
parent 25e94fc788
commit 73d55c84b0
2 changed files with 9 additions and 5 deletions

View File

@@ -78,9 +78,11 @@ impl<'a> TryFrom<&'a Node<'a, RefCell<Ast>>> for objects::Post {
}
NodeValue::BlockQuote => {
let mut p = Self::try_from(node.children())?.join_content("\n\n");
if p.content.len() > 0 {
if let BlockValue::Text(ref mut t) = &mut p.content[0] {
t.subtype = Some(BlockTextSubtype::Indented);
}
}
Ok(p)
}
NodeValue::Text(t) => {

View File

@@ -84,10 +84,12 @@ impl Post {
})
.flatten()
.collect::<Vec<_>>();
if self.content.len() > 0 {
let block = &mut self.content[0];
if let BlockValue::Text(ref mut t) = block {
t.text = String::from(t.text.strip_suffix(sep).unwrap_or(&t.text));
}
}
self
}
pub fn for_each_content<F>(mut self, f: F) -> Self