2022-12-18 03:18:43 -05:00
|
|
|
use super::parser_context::ContextElement;
|
|
|
|
use super::Context;
|
|
|
|
|
2023-03-23 16:40:39 -04:00
|
|
|
/// Check if we are below a section of the given section type regardless of depth
|
2022-12-18 03:30:28 -05:00
|
|
|
pub fn in_section<'r, 's, 'x>(context: Context<'r, 's>, section_name: &'x str) -> bool {
|
2022-12-18 03:18:43 -05:00
|
|
|
for thing in context.iter() {
|
|
|
|
match thing.get_data() {
|
|
|
|
ContextElement::Context(name) if *name == section_name => return true,
|
2023-03-23 16:40:39 -04:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Checks if we are currently an immediate child of the given section type
|
|
|
|
pub fn immediate_in_section<'r, 's, 'x>(context: Context<'r, 's>, section_name: &'x str) -> bool {
|
|
|
|
for thing in context.iter() {
|
|
|
|
match thing.get_data() {
|
|
|
|
ContextElement::Context(name) if *name == section_name => return true,
|
|
|
|
ContextElement::Context(name) if *name != section_name => return false,
|
|
|
|
_ => {}
|
2022-12-18 03:18:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
false
|
|
|
|
}
|