diff --git a/src/misc/markdown.rs b/src/misc/markdown.rs
index 69b3c3c..735b907 100644
--- a/src/misc/markdown.rs
+++ b/src/misc/markdown.rs
@@ -100,6 +100,7 @@ pub struct Metadata {
pub math: bool,
pub mermaid: bool,
pub syntax_highlight: bool,
+ pub mail_obfsucated: bool,
}
impl Metadata {
@@ -212,6 +213,7 @@ fn fix_images_and_integration(path: &str, html: String) -> (String, Metadata) {
math: false,
mermaid: false,
syntax_highlight: false,
+ mail_obfsucated: false,
};
(
@@ -284,14 +286,17 @@ pub fn read_md(
let mut html_content = String::from_utf8(html).unwrap();
let children_metadata;
+ let mail_obfsucated;
(html_content, children_metadata) = fix_images_and_integration(path, html_content);
html_content = custom_img_size(html_content);
+ (html_content, mail_obfsucated) = mail_obfuscation(html_content);
let mut final_metadata = Metadata {
info: metadata,
mermaid: check_mermaid(root, mermaid_name),
syntax_highlight: check_code(root, &[mermaid_name.into()]),
math: check_math(&html_content),
+ mail_obfsucated,
};
final_metadata.merge(children_metadata);
@@ -424,3 +429,32 @@ fn hljs_replace<'a>(root: &'a AstNode<'a>, mermaid_str: &str) {
}
});
}
+
+/// Obfuscate email if email found
+fn mail_obfuscation(html: String) -> (String, bool) {
+ let modified = Arc::new(AtomicBool::new(false));
+ (
+ rewrite_str(
+ &html,
+ RewriteStrSettings {
+ element_content_handlers: vec![element!("a[href^='mailto:']", |el| {
+ modified.store(true, Ordering::SeqCst);
+
+ let link = el.get_attribute("href").unwrap();
+ let (_uri, mail) = &link.split_at(7);
+ let (before, after) = mail.split_once('@').unwrap();
+
+ let modified_mail = format!("{}(at){}", before, after);
+
+ el.set_inner_content(&modified_mail, ContentType::Html);
+
+ // TODO: Change href
+ Ok(el.set_attribute("href", &link)?)
+ })],
+ ..RewriteStrSettings::default()
+ },
+ )
+ .unwrap(),
+ modified.load(Ordering::SeqCst),
+ )
+}
diff --git a/src/misc/utils.rs b/src/misc/utils.rs
index da27dec..3d5bf75 100644
--- a/src/misc/utils.rs
+++ b/src/misc/utils.rs
@@ -78,6 +78,7 @@ fn read_pdf(data: Vec) -> File {
mermaid: false,
syntax_highlight: false,
math: false,
+ mail_obfsucated: false,
},
content: format!(
r#"