2021-08-06 09:07:55 -04:00
|
|
|
pub use crate::cfg::Cfg;
|
2021-08-06 02:17:45 -04:00
|
|
|
use crate::minify::content::minify_content;
|
|
|
|
use crate::parse::content::parse_content;
|
2021-08-06 02:19:36 -04:00
|
|
|
use crate::parse::Code;
|
2021-08-06 02:17:45 -04:00
|
|
|
use crate::spec::tag::ns::Namespace;
|
2021-08-06 07:56:54 -04:00
|
|
|
use crate::spec::tag::EMPTY_SLICE;
|
2019-12-25 04:44:51 -05:00
|
|
|
|
2021-08-05 22:07:27 -04:00
|
|
|
mod ast;
|
2020-07-10 11:15:56 -04:00
|
|
|
mod cfg;
|
2020-06-19 03:58:16 -04:00
|
|
|
mod gen;
|
2021-08-06 02:17:45 -04:00
|
|
|
mod minify;
|
2021-08-05 22:07:27 -04:00
|
|
|
mod parse;
|
2019-12-29 19:52:45 -05:00
|
|
|
mod pattern;
|
2019-12-23 06:48:41 -05:00
|
|
|
mod spec;
|
2021-08-06 03:54:23 -04:00
|
|
|
#[cfg(test)]
|
2020-07-10 06:40:33 -04:00
|
|
|
mod tests;
|
2021-08-06 07:56:54 -04:00
|
|
|
mod whitespace;
|
2020-05-12 03:12:29 -04:00
|
|
|
|
2021-08-07 05:02:09 -04:00
|
|
|
/// Minifies UTF-8 HTML code, represented as an array of bytes.
|
2020-08-24 10:36:27 -04:00
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
///
|
|
|
|
/// * `code` - A slice of bytes representing the source code to minify.
|
|
|
|
/// * `cfg` - Configuration object to adjust minification approach.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```
|
2021-08-05 22:07:27 -04:00
|
|
|
/// use minify_html::{Cfg, minify};
|
2020-08-24 10:36:27 -04:00
|
|
|
///
|
2020-08-26 00:42:42 -04:00
|
|
|
/// let mut code: &[u8] = b"<p> Hello, world! </p>";
|
2021-08-07 00:56:20 -04:00
|
|
|
/// let mut cfg = Cfg::new();
|
|
|
|
/// cfg.keep_comments = true;
|
|
|
|
/// let minified = minify(&code, &cfg);
|
2021-08-05 22:07:27 -04:00
|
|
|
/// assert_eq!(minified, b"<p>Hello, world!".to_vec());
|
2020-08-24 10:36:27 -04:00
|
|
|
/// ```
|
2021-08-06 02:17:45 -04:00
|
|
|
pub fn minify(src: &[u8], cfg: &Cfg) -> Vec<u8> {
|
|
|
|
let mut code = Code::new(src);
|
2021-08-06 07:56:54 -04:00
|
|
|
let parsed = parse_content(&mut code, Namespace::Html, EMPTY_SLICE, EMPTY_SLICE);
|
2021-08-06 02:17:45 -04:00
|
|
|
let mut out = Vec::with_capacity(src.len());
|
2021-08-06 07:56:54 -04:00
|
|
|
minify_content(cfg, &mut out, false, EMPTY_SLICE, parsed.children);
|
2021-08-06 02:17:45 -04:00
|
|
|
out
|
2020-07-22 04:57:47 -04:00
|
|
|
}
|