Skip to content

Commit

Permalink
Extract fn
Browse files Browse the repository at this point in the history
  • Loading branch information
commonquail committed Sep 22, 2023
1 parent b35e8b9 commit ba23769
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,13 @@ pub fn parse(input: &str, comment_char: char) -> Vec<Token> {
} else if trailer.is_match(line) {
toks.push(Token::Trailer(line));
} else if let Some(y) = match toks.last_mut() {
Some(&mut Token::Footnote(_, ref mut b)) => {
b.push(' ');
b.push_str(line.trim());
None
}
Some(&mut Token::Paragraph(ref mut b)) => {
b.push(' ');
b.push_str(line.trim());
None
}
Some(&mut Token::Footnote(_, ref mut b)) => extend_prose_buffer_with_line(b, line),
Some(&mut Token::Paragraph(ref mut b)) => extend_prose_buffer_with_line(b, line),
Some(&mut Token::ListItem(_, _, ref mut b)) => {
if list_item.is_match(line) {
Some(list_item_from_line(&list_item, line))
} else {
b.push(' ');
b.push_str(line.trim());
None
extend_prose_buffer_with_line(b, line)
}
}
_ => {
Expand Down Expand Up @@ -180,6 +170,12 @@ fn list_item_from_line<'a>(pat: &Regex, line: &str) -> Token<'a> {
)
}

fn extend_prose_buffer_with_line(ref mut buf: &mut String, line: &str) -> Option<Token<'static>> {
buf.push(' ');
buf.push_str(line.trim());
None
}

#[cfg(test)]
mod tests {
use super::Token::*;
Expand Down

0 comments on commit ba23769

Please sign in to comment.