This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
md-pdf-rs/src/processors/head_cleanup.rs

21 lines
735 B
Rust
Raw Normal View History

2017-09-24 18:46:19 +01:00
use html::{sciter_start, get_html, destroy_matching, get_head, get_body};
2017-09-13 15:42:47 +01:00
use sciter::Element;
use config::Config;
2017-09-06 19:50:39 +01:00
pub fn head_cleanup(config: Config, input: String) -> Result<String, String> {
let mut root = sciter_start(input);
2017-09-06 17:52:39 +01:00
let mut head = get_head(&mut root);
2017-09-05 21:33:31 +01:00
destroy_matching(&mut head, "meta[content='text/css']");
destroy_matching(&mut head, "style");
destroy_matching(&mut head, "title");
2017-09-24 17:28:15 +01:00
2017-09-13 15:42:47 +01:00
let mut meta_charset = Element::create_at("meta", &mut head).unwrap();
2017-09-24 18:46:19 +01:00
meta_charset.set_attribute("charset", "UTF-8").expect("Failed to set charset");
2017-09-24 17:28:15 +01:00
let mut body = get_body(&mut root);
body.set_attribute("class", "content").expect("Failed to set body class");
2017-09-05 21:33:31 +01:00
return Ok(get_html(root));
}