mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 22:42:25 -04:00
Export static references from sound tags (#2420)
This commit is contained in:
parent
e23036ea8b
commit
84167d6e6b
1 changed files with 18 additions and 23 deletions
|
@ -168,7 +168,9 @@ lazy_static! {
|
||||||
/// Strings, src and data attributes with a leading underscore.
|
/// Strings, src and data attributes with a leading underscore.
|
||||||
static ref UNDERSCORED_REFERENCES: Regex = Regex::new(
|
static ref UNDERSCORED_REFERENCES: Regex = Regex::new(
|
||||||
r#"(?x)
|
r#"(?x)
|
||||||
"(_[^"]+)" # double quoted
|
\[sound:(_[^]]+)\] # a filename in an Anki sound tag
|
||||||
|
| # or
|
||||||
|
"(_[^"]+)" # a double quoted
|
||||||
| # or
|
| # or
|
||||||
'(_[^']+)' # single quoted string
|
'(_[^']+)' # single quoted string
|
||||||
| # or
|
| # or
|
||||||
|
@ -312,31 +314,24 @@ pub fn replace_media_refs(
|
||||||
pub(crate) fn extract_underscored_css_imports(text: &str) -> Vec<&str> {
|
pub(crate) fn extract_underscored_css_imports(text: &str) -> Vec<&str> {
|
||||||
UNDERSCORED_CSS_IMPORTS
|
UNDERSCORED_CSS_IMPORTS
|
||||||
.captures_iter(text)
|
.captures_iter(text)
|
||||||
.map(|caps| {
|
.map(extract_match)
|
||||||
caps.get(1)
|
|
||||||
.or_else(|| caps.get(2))
|
|
||||||
.or_else(|| caps.get(3))
|
|
||||||
.or_else(|| caps.get(4))
|
|
||||||
.or_else(|| caps.get(5))
|
|
||||||
.unwrap()
|
|
||||||
.as_str()
|
|
||||||
})
|
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn extract_underscored_references(text: &str) -> Vec<&str> {
|
pub(crate) fn extract_underscored_references(text: &str) -> Vec<&str> {
|
||||||
UNDERSCORED_REFERENCES
|
UNDERSCORED_REFERENCES
|
||||||
.captures_iter(text)
|
.captures_iter(text)
|
||||||
.map(|caps| {
|
.map(extract_match)
|
||||||
caps.get(1)
|
|
||||||
.or_else(|| caps.get(2))
|
|
||||||
.or_else(|| caps.get(3))
|
|
||||||
.unwrap()
|
|
||||||
.as_str()
|
|
||||||
})
|
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the first matching group as a str. This is intended for regexes
|
||||||
|
/// where exactly one group matches, and will panic for matches without matching
|
||||||
|
/// groups.
|
||||||
|
fn extract_match(caps: Captures) -> &str {
|
||||||
|
caps.iter().skip(1).find_map(|g| g).unwrap().as_str()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn strip_html_preserving_media_filenames(html: &str) -> Cow<str> {
|
pub fn strip_html_preserving_media_filenames(html: &str) -> Cow<str> {
|
||||||
HTML_MEDIA_TAGS
|
HTML_MEDIA_TAGS
|
||||||
.replace_all(html, r" ${1}${2}${3} ")
|
.replace_all(html, r" ${1}${2}${3} ")
|
||||||
|
|
Loading…
Reference in a new issue