minify_html/cfg/mod.rs
1/// Configuration settings that can be adjusted and passed to a minification function to change the
2/// minification approach.
3#[derive(Clone, Default)]
4pub struct Cfg {
5 /// Do not minify DOCTYPEs. Minified DOCTYPEs may not be spec compliant.
6 pub do_not_minify_doctype: bool,
7 /// 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).
8 pub ensure_spec_compliant_unquoted_attribute_values: bool,
9 /// Do not omit closing tags when possible.
10 pub keep_closing_tags: bool,
11 /// Do not omit `<html>` and `<head>` opening tags when they don't have attributes.
12 pub keep_html_and_head_opening_tags: bool,
13 /// Keep spaces between attributes when possible to conform to HTML standards.
14 pub keep_spaces_between_attributes: bool,
15 /// Keep all comments.
16 pub keep_comments: bool,
17 /// Keep `type=text` attribute name and value on `<input>` elements.
18 pub keep_input_type_text_attr: bool,
19 /// Keep SSI comments.
20 pub keep_ssi_comments: bool,
21 /// When `{{`, `{#`, or `{%` are seen in content, all source code until the subsequent matching closing `}}`, `#}`, or `%}` respectively gets piped through untouched.
22 pub preserve_brace_template_syntax: bool,
23 /// When `<%` is seen in content, all source code until the subsequent matching closing `%>` gets piped through untouched.
24 pub preserve_chevron_percent_template_syntax: bool,
25 /// Minify CSS in `<style>` tags and `style` attributes using [https://github.com/parcel-bundler/lightningcss](lightningcss).
26 pub minify_css: bool,
27 /// Minify JavaScript in `<script>` tags using
28 /// [minify-js](https://github.com/wilsonzlin/minify-js).
29 ///
30 /// Only `<script>` tags with a valid or no
31 /// [MIME type](https://mimesniff.spec.whatwg.org/#javascript-mime-type) is considered to
32 /// contain JavaScript, as per the specification.
33 pub minify_js: bool,
34 /// Remove all bangs.
35 pub remove_bangs: bool,
36 /// Remove all processing_instructions.
37 pub remove_processing_instructions: bool,
38}
39
40impl Cfg {
41 pub fn new() -> Cfg {
42 Cfg::default()
43 }
44
45 pub fn spec_compliant() -> Cfg {
46 Cfg {
47 do_not_minify_doctype: true,
48 ensure_spec_compliant_unquoted_attribute_values: true,
49 keep_spaces_between_attributes: true,
50 ..Cfg::default()
51 }
52 }
53}