w3c compliance

This commit is contained in:
Mylloon 2024-06-02 18:44:57 +02:00
parent bf9217ba84
commit d1d21bc68c
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 16 additions and 12 deletions

View file

@ -428,6 +428,8 @@ fn hljs_replace<'a>(root: &'a AstNode<'a>, mermaid_str: &str) {
fn mail_obfuscation(html: &str) -> (String, bool) {
let modified = Arc::new(AtomicBool::new(false));
let data_attr = "title";
// Modify HTML for mails
let new_html = rewrite_str(
html,
@ -441,8 +443,8 @@ fn mail_obfuscation(html: &str) -> (String, bool) {
let (before, after) = mail.split_once('@').unwrap();
// Preserve old data and add obfuscated mail address
el.prepend("<span data='", ContentType::Html);
let modified_mail = format!("' />{before}<span class='at'>(at)</span>{after}");
el.prepend(&format!("<span {data_attr}='"), ContentType::Html);
let modified_mail = format!("'></span>{before}<span class='at'>(at)</span>{after}");
el.append(&modified_mail, ContentType::Html);
// Change href
@ -462,12 +464,12 @@ fn mail_obfuscation(html: &str) -> (String, bool) {
&new_html,
RewriteStrSettings {
element_content_handlers: vec![element!(
"a[href^='mailto:'] > span[data]",
&format!("a[href^='mailto:'] > span[{data_attr}]"),
|el| {
Ok(el.set_attribute(
"data",
data_attr,
// Remove mails
&el.get_attribute("data")
&el.get_attribute(data_attr)
.unwrap()
.split_whitespace()
.filter(|word| !word.contains('@'))

View file

@ -1,18 +1,20 @@
window.addEventListener("load", () => {
Array.from(document.getElementsByClassName("at")).forEach((elem) => {
const span = elem.parentElement;
const a = elem.parentElement;
const span = elem.previousElementSibling;
// Replace (at) by @
elem.outerHTML = "@";
// Remove useless span
const a = span.parentElement;
// Correct text
const data = span.getAttribute("data");
a.innerHTML = data.length > 0 ? data : span.textContent;
const data = span.getAttribute("title");
if (data.length > 0) {
a.innerHTML = data;
} else {
a.style = "hyphens: none;";
}
// Change link
a.setAttribute("href", a.getAttribute("href").replace(" at ", "@"));
a.setAttribute("href", a.textContent);
});
});