2020-08-24 10:36:27 -04:00
/// Configuration settings that can be adjusted and passed to a minification function to change the
/// minification approach.
2021-08-10 00:31:08 -04:00
#[ derive(Default) ]
2020-07-10 11:15:56 -04:00
pub struct Cfg {
2021-08-10 03:45:37 -04:00
/// Do not minify DOCTYPEs. Minified DOCTYPEs may not be spec compliant.
pub do_not_minify_doctype : bool ,
2021-08-07 11:45:25 -04:00
/// Ensure all unquoted attribute values in the output do not contain any characters prohibited by the [WHATWG specification](https://html.spec.whatwg.org/multipage/syntax.html#attributes-2).
pub ensure_spec_compliant_unquoted_attribute_values : bool ,
2021-08-07 00:56:20 -04:00
/// Do not omit closing tags when possible.
pub keep_closing_tags : bool ,
2021-08-07 01:59:41 -04:00
/// Do not omit `<html>` and `<head>` opening tags when they don't have attributes.
pub keep_html_and_head_opening_tags : bool ,
2021-08-07 00:56:20 -04:00
/// Keep spaces between attributes when possible to conform to HTML standards.
pub keep_spaces_between_attributes : bool ,
/// Keep all comments.
pub keep_comments : bool ,
2023-02-16 03:23:03 -05:00
/// Minify CSS in `<style>` tags and `style` attributes using [https://github.com/Mnwa/css-minify](css-minify). By default, the optimisation level is 1 as specified by the CSS minifier, but this can be adjusted by the minify_css_level_* settings.
2021-08-07 06:02:20 -04:00
pub minify_css : bool ,
2023-02-16 03:23:03 -05:00
/// Use optimisation level 1 for the CSS minifier. This is currently the default, but may change in the future if higher levels become safe.
pub minify_css_level_1 : bool ,
/// Use optimisation level 2 for the CSS minifier. This is mostly safe, but may perform some dangerous optimisations.
pub minify_css_level_2 : bool ,
/// Use optimisation level 3 for the CSS minifier. This performs many dangerous optimisations, so ensure any input works with this level.
pub minify_css_level_3 : bool ,
/// Minify JavaScript in `<script>` tags using
2022-06-21 03:29:12 -04:00
/// [minify-js](https://github.com/wilsonzlin/minify-js).
2021-08-07 06:02:20 -04:00
///
/// Only `<script>` tags with a valid or no
/// [MIME type](https://mimesniff.spec.whatwg.org/#javascript-mime-type) is considered to
/// contain JavaScript, as per the specification.
pub minify_js : bool ,
2021-08-06 02:17:45 -04:00
/// Remove all bangs.
pub remove_bangs : bool ,
/// Remove all processing_instructions.
pub remove_processing_instructions : bool ,
2020-07-10 11:15:56 -04:00
}
2021-08-07 00:56:20 -04:00
impl Cfg {
pub fn new ( ) -> Cfg {
2021-08-10 00:31:08 -04:00
Cfg ::default ( )
2021-08-07 00:56:20 -04:00
}
2021-08-10 00:23:33 -04:00
pub fn spec_compliant ( ) -> Cfg {
Cfg {
2021-08-10 03:45:37 -04:00
do_not_minify_doctype : true ,
2021-08-10 00:23:33 -04:00
ensure_spec_compliant_unquoted_attribute_values : true ,
keep_spaces_between_attributes : true ,
2021-08-10 00:31:08 -04:00
.. Cfg ::default ( )
2021-08-10 00:23:33 -04:00
}
}
}