From d933d7774f4209e497fb912b387ea7adec7ebf42 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Wed, 30 Dec 2020 18:00:06 +0100 Subject: [PATCH] Add Alt text to latex image I'm trying to go over accessibilities issues in AnkiDroid. Since we'll use rust backend, I thought I might as well go over it in rust directly. The only side effect in anki is that, if you copy a text with the image, you'll get the LaTeX copied instead of nothing. Alas, it seems qt does not show alt text. --- rslib/src/latex.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/rslib/src/latex.rs b/rslib/src/latex.rs index 86800c8b8..48ad2100b 100644 --- a/rslib/src/latex.rs +++ b/rslib/src/latex.rs @@ -66,7 +66,7 @@ pub(crate) fn extract_latex(text: &str, svg: bool) -> (String, Vec String { format!("latex-{}.{}", csum, ext) } -fn image_link_for_fname(fname: &str) -> String { - format!("", fname) +fn image_link_for_fname(src: &str, fname: &str) -> String { + format!( + "\"{}\"", + htmlescape::encode_attribute(src), + fname + ) } #[cfg(test)] @@ -111,7 +115,10 @@ mod test { assert_eq!( extract_latex("a[latex]one
and
two[/latex]b", false), ( - format!("ab", fname), + format!( + "a\"one
and
two\"b", + fname + ), vec![ExtractedLatex { fname: fname.into(), latex: "one\nand\ntwo".into()