mirror of
https://github.com/ankitects/anki.git
synced 2026-01-13 14:03:55 -05:00
update cloze.rs
This commit is contained in:
parent
45afe21630
commit
462c0b7c9f
1 changed files with 6 additions and 4 deletions
|
|
@ -15,6 +15,7 @@ use nom::bytes::complete::tag;
|
|||
use nom::bytes::complete::take_while;
|
||||
use nom::combinator::map;
|
||||
use nom::IResult;
|
||||
use nom::Parser;
|
||||
use regex::Captures;
|
||||
use regex::Regex;
|
||||
|
||||
|
|
@ -72,7 +73,7 @@ fn tokenize(mut text: &str) -> impl Iterator<Item = Token> {
|
|||
}
|
||||
|
||||
fn close_cloze(text: &str) -> IResult<&str, Token> {
|
||||
map(tag("}}"), |_| Token::CloseCloze)(text)
|
||||
map(tag("}}"), |_| Token::CloseCloze).parse(text)
|
||||
}
|
||||
|
||||
/// Match a run of text until an open/close marker is encountered.
|
||||
|
|
@ -87,7 +88,7 @@ fn tokenize(mut text: &str) -> impl Iterator<Item = Token> {
|
|||
// start with the no-match case
|
||||
let mut index = text.len();
|
||||
for (idx, _) in text.char_indices() {
|
||||
if other_token(&text[idx..]).is_ok() {
|
||||
if other_token.parse(&text[idx..]).is_ok() {
|
||||
index = idx;
|
||||
break;
|
||||
}
|
||||
|
|
@ -99,8 +100,9 @@ fn tokenize(mut text: &str) -> impl Iterator<Item = Token> {
|
|||
if text.is_empty() {
|
||||
None
|
||||
} else {
|
||||
let (remaining_text, token) =
|
||||
alt((open_cloze, close_cloze, normal_text))(text).unwrap();
|
||||
let (remaining_text, token) = alt((open_cloze, close_cloze, normal_text))
|
||||
.parse(text)
|
||||
.unwrap();
|
||||
text = remaining_text;
|
||||
Some(token)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue