handle mathjax+cloze case
instead of trying to selectively change clozes from c to C, just strip HTML from inside the mathjax sections instead
This commit is contained in:
parent
cc09ca34d4
commit
389bf07b52
@ -68,8 +68,9 @@ fn apply_filter<'a>(filter_name: &str, text: &'a str, field_name: &str) -> (bool
|
||||
match base {
|
||||
"type" => type_filter(text, filter_args, field_name),
|
||||
"hint" => hint_filter(text, field_name),
|
||||
//"cq" => cloze_filter(text, filter_args, true),
|
||||
//"ca" => cloze_filter(text, filter_args, false),
|
||||
"cq" => cloze_filter(text, filter_args, true),
|
||||
"ca" => cloze_filter(text, filter_args, false),
|
||||
// unrecognized filter
|
||||
_ => return (false, None),
|
||||
}
|
||||
}
|
||||
@ -100,6 +101,14 @@ lazy_static! {
|
||||
"#
|
||||
)
|
||||
.unwrap();
|
||||
static ref MATHJAX: Regex = Regex::new(
|
||||
r#"(?xsi)
|
||||
(\\[(\[]) # 1 = mathjax opening tag
|
||||
(.*?) # 2 = inner content
|
||||
(\\[])]) # 3 = mathjax closing tag
|
||||
"#
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
mod cloze_caps {
|
||||
@ -113,6 +122,12 @@ mod cloze_caps {
|
||||
pub static HINT: usize = 4;
|
||||
}
|
||||
|
||||
mod mathjax_caps {
|
||||
pub static OPENING_TAG: usize = 1;
|
||||
pub static INNER_TEXT: usize = 2;
|
||||
pub static CLOSING_TAG: usize = 3;
|
||||
}
|
||||
|
||||
fn reveal_cloze_text(text: &str, ord: u16, question: bool) -> Cow<str> {
|
||||
let output = CLOZE.replace_all(text, |caps: &Captures| {
|
||||
let captured_ord = caps
|
||||
@ -154,10 +169,22 @@ fn reveal_cloze_text(text: &str, ord: u16, question: bool) -> Cow<str> {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn strip_html_inside_mathjax(text: &str) -> Cow<str> {
|
||||
MATHJAX.replace_all(text, |caps: &Captures| -> String {
|
||||
format!(
|
||||
"{}{}{}",
|
||||
caps.get(mathjax_caps::OPENING_TAG).unwrap().as_str(),
|
||||
strip_html(caps.get(mathjax_caps::INNER_TEXT).unwrap().as_str()).as_ref(),
|
||||
caps.get(mathjax_caps::CLOSING_TAG).unwrap().as_str()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn cloze_filter<'a>(text: &'a str, filter_args: &str, question: bool) -> Cow<'a, str> {
|
||||
let cloze_ord = filter_args.parse().unwrap_or(0);
|
||||
reveal_cloze_text(text, cloze_ord, question)
|
||||
strip_html_inside_mathjax(reveal_cloze_text(text, cloze_ord, question).as_ref())
|
||||
.into_owned()
|
||||
.into()
|
||||
}
|
||||
|
||||
// Ruby filters
|
||||
|
Loading…
Reference in New Issue
Block a user