mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
Add AV prettifier for use in browser table
This commit is contained in:
parent
e033525fc3
commit
5b5e6d7c72
3 changed files with 29 additions and 3 deletions
|
@ -9,7 +9,7 @@ use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
card::{CardQueue, CardType},
|
card::{CardQueue, CardType},
|
||||||
card_rendering::extract_av_tags,
|
card_rendering::prettify_av_tags,
|
||||||
notetype::{CardTemplate, NotetypeKind},
|
notetype::{CardTemplate, NotetypeKind},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
scheduler::{timespan::time_span, timing::SchedTimingToday},
|
scheduler::{timespan::time_span, timing::SchedTimingToday},
|
||||||
|
@ -271,7 +271,7 @@ impl RenderContext {
|
||||||
} => current_text,
|
} => current_text,
|
||||||
})
|
})
|
||||||
.join("");
|
.join("");
|
||||||
let question = extract_av_tags(&qnodes_text, true, &col.tr).0;
|
let question = prettify_av_tags(&qnodes_text);
|
||||||
|
|
||||||
Ok(RenderContext {
|
Ok(RenderContext {
|
||||||
question,
|
question,
|
||||||
|
@ -411,7 +411,7 @@ impl RowContext {
|
||||||
} => current_text,
|
} => current_text,
|
||||||
})
|
})
|
||||||
.join("");
|
.join("");
|
||||||
let answer = extract_av_tags(&answer, false, &self.tr).0;
|
let answer = prettify_av_tags(&answer);
|
||||||
html_to_text_line(
|
html_to_text_line(
|
||||||
if let Some(stripped) = answer.strip_prefix(&render_context.question) {
|
if let Some(stripped) = answer.strip_prefix(&render_context.question) {
|
||||||
stripped
|
stripped
|
||||||
|
|
|
@ -17,6 +17,10 @@ pub fn extract_av_tags(txt: &str, question_side: bool, tr: &I18n) -> (String, Ve
|
||||||
CardNodes::parse(txt).write_and_extract_av_tags(question_side, tr)
|
CardNodes::parse(txt).write_and_extract_av_tags(question_side, tr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn prettify_av_tags(txt: &str) -> String {
|
||||||
|
CardNodes::parse(txt).write_with_pretty_av_tags()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
struct CardNodes<'a>(Vec<Node<'a>>);
|
struct CardNodes<'a>(Vec<Node<'a>>);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,10 @@ impl<'a> CardNodes<'a> {
|
||||||
let mut extractor = AvExtractor::new(question_side, tr);
|
let mut extractor = AvExtractor::new(question_side, tr);
|
||||||
(extractor.write(self), extractor.tags)
|
(extractor.write(self), extractor.tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn write_with_pretty_av_tags(&self) -> String {
|
||||||
|
AvPrettifier::new().write(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait Write {
|
trait Write {
|
||||||
|
@ -168,6 +172,24 @@ impl Write for AvExtractor<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct AvPrettifier;
|
||||||
|
|
||||||
|
impl AvPrettifier {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Write for AvPrettifier {
|
||||||
|
fn write_sound(&mut self, buf: &mut String, resource: &str) {
|
||||||
|
write!(buf, "🔉{}🔉", resource).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_tts_tag(&mut self, buf: &mut String, tag: &TtsTag) {
|
||||||
|
write!(buf, "💬{}💬", tag.content).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in a new issue