mirror of
https://github.com/lise-henry/crowbook
synced 2024-05-28 14:06:29 +02:00
Add is_container method to token and use it in parser
This commit is contained in:
parent
abd4efee31
commit
20d9ea7fb3
|
@ -187,14 +187,8 @@ impl Parser {
|
|||
|
||||
// Transform superscript and subscript
|
||||
if self.superscript {
|
||||
// for mut token in &mut res {
|
||||
self.parse_super_vec(&mut res);
|
||||
self.parse_sub_vec(&mut res);
|
||||
// if let Some(mut v) = token.inner_mut() {
|
||||
// self.parse_super_vec(&mut v);
|
||||
// self.parse_sub_vec(&mut v);
|
||||
// }
|
||||
// }
|
||||
self.parse_super_vec(&mut res);
|
||||
self.parse_sub_vec(&mut res);
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
|
@ -278,7 +272,7 @@ impl Parser {
|
|||
unreachable!()
|
||||
}
|
||||
} else {
|
||||
if v[i].is_code() {
|
||||
if v[i].is_code() || !v[i].is_container() {
|
||||
continue;
|
||||
}
|
||||
if let Some(ref mut inner) = v[i].inner_mut() {
|
||||
|
@ -308,7 +302,7 @@ impl Parser {
|
|||
unreachable!()
|
||||
}
|
||||
} else {
|
||||
if v[i].is_code() {
|
||||
if v[i].is_code() || !v[i].is_container() {
|
||||
continue;
|
||||
}
|
||||
if let Some(ref mut inner) = v[i].inner_mut() {
|
||||
|
|
|
@ -201,4 +201,17 @@ impl Token {
|
|||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if token is a container (paragraph, quote, code block, code, emphasis, ..., but not links, images, and so on).
|
||||
pub fn is_container(&self) -> bool {
|
||||
match *self {
|
||||
Token::CodeBlock(..) | Token::Code(..) | Token::Paragraph(..)
|
||||
| Token::Header(..) | Token::Emphasis(..) | Token::Strong(..)
|
||||
| Token::List(..) | Token::OrderedList(..) | Token::Table(..)
|
||||
| Token::TableHead(..) | Token::TableRow(..) | Token::Footnote(..)
|
||||
| Token::TableCell(..) | Token::Annotation(..) | Token::Item(..)
|
||||
| Token::BlockQuote(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue