w3c compliance
This commit is contained in:
parent
bf9217ba84
commit
d1d21bc68c
2 changed files with 16 additions and 12 deletions
|
@ -428,6 +428,8 @@ fn hljs_replace<'a>(root: &'a AstNode<'a>, mermaid_str: &str) {
|
||||||
fn mail_obfuscation(html: &str) -> (String, bool) {
|
fn mail_obfuscation(html: &str) -> (String, bool) {
|
||||||
let modified = Arc::new(AtomicBool::new(false));
|
let modified = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
|
let data_attr = "title";
|
||||||
|
|
||||||
// Modify HTML for mails
|
// Modify HTML for mails
|
||||||
let new_html = rewrite_str(
|
let new_html = rewrite_str(
|
||||||
html,
|
html,
|
||||||
|
@ -441,8 +443,8 @@ fn mail_obfuscation(html: &str) -> (String, bool) {
|
||||||
let (before, after) = mail.split_once('@').unwrap();
|
let (before, after) = mail.split_once('@').unwrap();
|
||||||
|
|
||||||
// Preserve old data and add obfuscated mail address
|
// Preserve old data and add obfuscated mail address
|
||||||
el.prepend("<span data='", ContentType::Html);
|
el.prepend(&format!("<span {data_attr}='"), ContentType::Html);
|
||||||
let modified_mail = format!("' />{before}<span class='at'>(at)</span>{after}");
|
let modified_mail = format!("'></span>{before}<span class='at'>(at)</span>{after}");
|
||||||
el.append(&modified_mail, ContentType::Html);
|
el.append(&modified_mail, ContentType::Html);
|
||||||
|
|
||||||
// Change href
|
// Change href
|
||||||
|
@ -462,12 +464,12 @@ fn mail_obfuscation(html: &str) -> (String, bool) {
|
||||||
&new_html,
|
&new_html,
|
||||||
RewriteStrSettings {
|
RewriteStrSettings {
|
||||||
element_content_handlers: vec![element!(
|
element_content_handlers: vec![element!(
|
||||||
"a[href^='mailto:'] > span[data]",
|
&format!("a[href^='mailto:'] > span[{data_attr}]"),
|
||||||
|el| {
|
|el| {
|
||||||
Ok(el.set_attribute(
|
Ok(el.set_attribute(
|
||||||
"data",
|
data_attr,
|
||||||
// Remove mails
|
// Remove mails
|
||||||
&el.get_attribute("data")
|
&el.get_attribute(data_attr)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
.filter(|word| !word.contains('@'))
|
.filter(|word| !word.contains('@'))
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
window.addEventListener("load", () => {
|
window.addEventListener("load", () => {
|
||||||
Array.from(document.getElementsByClassName("at")).forEach((elem) => {
|
Array.from(document.getElementsByClassName("at")).forEach((elem) => {
|
||||||
const span = elem.parentElement;
|
const a = elem.parentElement;
|
||||||
|
const span = elem.previousElementSibling;
|
||||||
|
|
||||||
// Replace (at) by @
|
// Replace (at) by @
|
||||||
elem.outerHTML = "@";
|
elem.outerHTML = "@";
|
||||||
|
|
||||||
// Remove useless span
|
|
||||||
const a = span.parentElement;
|
|
||||||
|
|
||||||
// Correct text
|
// Correct text
|
||||||
const data = span.getAttribute("data");
|
const data = span.getAttribute("title");
|
||||||
a.innerHTML = data.length > 0 ? data : span.textContent;
|
if (data.length > 0) {
|
||||||
|
a.innerHTML = data;
|
||||||
|
} else {
|
||||||
|
a.style = "hyphens: none;";
|
||||||
|
}
|
||||||
|
|
||||||
// Change link
|
// Change link
|
||||||
a.setAttribute("href", a.getAttribute("href").replace(" at ", "@"));
|
a.setAttribute("href", a.textContent);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue