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 /// Allow unquoted attribute values in the output to contain characters prohibited by the [WHATWG specification](https://html.spec.whatwg.org/multipage/syntax.html#attributes-2). These will still be parsed correctly by almost all browsers.
6 pub allow_noncompliant_unquoted_attribute_values: bool,
7 /// Allow some minifications around entities that may not pass validation, but will still be parsed correctly by almost all browsers.
8 pub allow_optimal_entities: bool,
9 /// Allow removing_spaces between attributes when possible, which may not be spec compliant. These will still be parsed correctly by almost all browsers.
10 pub allow_removing_spaces_between_attributes: bool,
11 /// Do not omit closing tags when possible.
12 pub keep_closing_tags: bool,
13 /// Keep all comments.
14 pub keep_comments: bool,
15 /// Do not omit `<html>` and `<head>` opening tags when they don't have attributes.
16 pub keep_html_and_head_opening_tags: 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 /// Minify CSS in `<style>` tags and `style` attributes using [https://github.com/parcel-bundler/lightningcss](lightningcss).
22 pub minify_css: bool,
23 /// Minify DOCTYPEs. Minified DOCTYPEs may not be spec compliant, but will still be parsed correctly by almost all browsers.
24 pub minify_doctype: bool,
25 /// Minify JavaScript in `<script>` tags using [minify-js](https://github.com/wilsonzlin/minify-js).
26 pub minify_js: bool,
27 /// When `{{`, `{#`, or `{%` are seen in content, all source code until the subsequent matching closing `}}`, `#}`, or `%}` respectively gets piped through untouched.
28 pub preserve_brace_template_syntax: bool,
29 /// When `<%` is seen in content, all source code until the subsequent matching closing `%>` gets piped through untouched.
30 pub preserve_chevron_percent_template_syntax: bool,
31 /// Remove all bangs.
32 pub remove_bangs: bool,
33 /// Remove all processing instructions.
34 pub remove_processing_instructions: bool,
35}
36
37impl Cfg {
38 pub fn new() -> Cfg {
39 Cfg::default()
40 }
41
42 pub fn enable_possibly_noncompliant(&mut self) {
43 self.allow_noncompliant_unquoted_attribute_values = true;
44 self.allow_optimal_entities = true;
45 self.allow_removing_spaces_between_attributes = true;
46 self.minify_doctype = true;
47 }
48}