1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
use html5ever::rcdom::Handle; use std::fmt; use url::percent_encoding::{QUERY_ENCODE_SET, percent_encode}; pub mod parser; pub mod manipulator; #[cfg(test)] mod fixtures; #[cfg(test)] mod parser_tests; #[cfg(test)] mod manipulator_tests; pub struct Entry { handle: Handle, pub entry_type: String, pub entry_name: String, pub anchor_name: String, pub is_section: bool, } static mut N: i32 = 5; impl Entry { fn new(e: Handle, entry_type: &str, entry_name: Option<String>, is_section: bool) -> Option<Entry> { match entry_name { Some(entry_name) => { let anchor_name = format!("//dash_ref_{id}/{type}/{name}/{is_section}", id = unsafe { N += 1; N }, type = entry_type, name = percent_encode(entry_name.rsplit("::") .nth(0) .unwrap() .as_bytes(), QUERY_ENCODE_SET) .collect::<String>(), is_section = if is_section { "1" } else { "0" }); Some(Entry { handle: e, entry_name: entry_name, entry_type: String::from(entry_type), anchor_name: anchor_name, is_section: is_section, }) } None => None, } } } impl fmt::Display for Entry { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:>15} | {:30} | {:5} | {}", self.entry_type, self.entry_name, self.is_section, self.anchor_name) } }