marcus/core/
inline_ignore.rs

1use crate::helpers::{id, re};
2use regex::Captures;
3use std::collections::HashMap;
4
5pub fn hide(html: &mut String) -> HashMap<i32, String> {
6  // Store ignored scripts & styles
7  let mut ignore: HashMap<i32, String> = HashMap::new();
8
9  // Parse: Inline ignore script
10  re::parse(html, re::from(re::INLINE_SCRIPT), | capture: Captures | {
11    // Create a unique ID
12    let mut id: i32 = id::random_10_digit();
13    while ignore.contains_key(&id) {
14      id = id::random_10_digit();
15    }
16    // 1. Create the text ID for the ignored script and nsert it into the ignore hashmap
17    let text_id: String = format!("?{}?", &id);
18    ignore.insert(id, capture[0].to_string());
19    // Return the text ID string as the temporary value
20    text_id
21  });
22
23  // Parse: Inline ignore style
24  re::parse(html, re::from(re::INLINE_STYLE), | capture: Captures | {
25    // Create a unique ID
26    let mut id: i32 = id::random_10_digit();
27    while ignore.contains_key(&id) {
28      id = id::random_10_digit();
29    }
30    // 1. Create the text ID for the ignored style and nsert it into the ignore hashmap
31    let text_id: String = format!("?{}?", &id);
32    ignore.insert(id, capture[0].to_string());
33    // Return the text ID string as the temporary value
34    text_id
35  });
36
37  // Return a hashmap containing the ignored scripts & styles
38  ignore
39}
40
41pub fn show(html: &mut String, ignore: HashMap<i32, String>) {
42  for (id, original) in ignore {
43    *html = html.replace(&format!("?{}?", id), &original);
44  }
45}