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
use std::io::Write;
use crate::ast::c14n::c14n_serialise_ast;
pub use crate::cfg::Cfg;
use crate::common::spec::tag::ns::Namespace;
use crate::common::spec::tag::EMPTY_SLICE;
use crate::minify::content::minify_content;
use crate::parse::content::parse_content;
use crate::parse::Code;
mod ast;
mod cfg;
mod common;
mod entity;
mod minify;
mod parse;
#[cfg(test)]
mod tests;
pub fn minify(src: &[u8], cfg: &Cfg) -> Vec<u8> {
let mut code = Code::new(src);
let parsed = parse_content(&mut code, Namespace::Html, EMPTY_SLICE, EMPTY_SLICE);
let mut out = Vec::with_capacity(src.len());
minify_content(
cfg,
&mut out,
Namespace::Html,
false,
EMPTY_SLICE,
parsed.children,
);
out
}
pub fn canonicalise<T: Write>(out: &mut T, src: &[u8]) -> std::io::Result<()> {
let mut code = Code::new(src);
let parsed = parse_content(&mut code, Namespace::Html, EMPTY_SLICE, EMPTY_SLICE);
for c in parsed.children {
c14n_serialise_ast(out, &c)?;
}
Ok(())
}