Move another function inside bold that was only used by bold.
This commit is contained in:
parent
eaf8721ae9
commit
a005502d97
@ -10,9 +10,9 @@ use super::text::symbol;
|
||||
use super::text::Bold;
|
||||
use super::text::Res;
|
||||
use super::text::TextElement;
|
||||
use super::text_element_parser::_preceded_by_whitespace;
|
||||
use super::text_element_parser::flat_text_element;
|
||||
use super::text_element_parser::in_section;
|
||||
use super::token::Token;
|
||||
use super::Context;
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
@ -70,3 +70,36 @@ fn bold_start(input: &str) -> Res<&str, TextElement> {
|
||||
fn bold_end(input: &str) -> Res<&str, TextElement> {
|
||||
map(symbol("*"), TextElement::Symbol)(input)
|
||||
}
|
||||
|
||||
fn _preceded_by_whitespace<'s, 'r>(context: Context<'r, 's>) -> bool {
|
||||
let mut context_iterator = context.iter().enumerate();
|
||||
loop {
|
||||
if let Some((i, ctx)) = context_iterator.next() {
|
||||
match ctx.get_data() {
|
||||
ContextElement::ExitMatcherNode(_) => {}
|
||||
ContextElement::PreviousElementNode(previous_element_node) => {
|
||||
match &previous_element_node.element {
|
||||
Token::TextElement(text_element) => {
|
||||
match text_element {
|
||||
TextElement::Span(_) => return false,
|
||||
TextElement::Space(_) => return true,
|
||||
TextElement::LineBreak(_) => return true,
|
||||
TextElement::Symbol(_) => return false,
|
||||
TextElement::Bold(_) => return false,
|
||||
TextElement::Link(_) => return false,
|
||||
};
|
||||
}
|
||||
Token::Paragraph(_) => unreachable!(),
|
||||
};
|
||||
}
|
||||
ContextElement::StartOfParagraph => {
|
||||
return true;
|
||||
}
|
||||
ContextElement::Context(_) => {}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
@ -48,39 +48,6 @@ pub fn in_section<'s, 'r, 'x>(context: Context<'r, 's>, section_name: &'x str) -
|
||||
false
|
||||
}
|
||||
|
||||
pub fn _preceded_by_whitespace<'s, 'r>(context: Context<'r, 's>) -> bool {
|
||||
let mut context_iterator = context.iter().enumerate();
|
||||
loop {
|
||||
if let Some((i, ctx)) = context_iterator.next() {
|
||||
match ctx.get_data() {
|
||||
ContextElement::ExitMatcherNode(_) => {}
|
||||
ContextElement::PreviousElementNode(previous_element_node) => {
|
||||
match &previous_element_node.element {
|
||||
Token::TextElement(text_element) => {
|
||||
match text_element {
|
||||
TextElement::Span(_) => return false,
|
||||
TextElement::Space(_) => return true,
|
||||
TextElement::LineBreak(_) => return true,
|
||||
TextElement::Symbol(_) => return false,
|
||||
TextElement::Bold(_) => return false,
|
||||
TextElement::Link(_) => return false,
|
||||
};
|
||||
}
|
||||
Token::Paragraph(_) => unreachable!(),
|
||||
};
|
||||
}
|
||||
ContextElement::StartOfParagraph => {
|
||||
return true;
|
||||
}
|
||||
ContextElement::Context(_) => {}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub fn flat_text_element<'s, 'r>(
|
||||
context: Context<'r, 's>,
|
||||
i: &'s str,
|
||||
|
Loading…
Reference in New Issue
Block a user