Skip to main content

min_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  #[cfg(feature = "lightningcss")]
22  /// Minify CSS in `<style>` tags and `style` attributes using [https://github.com/parcel-bundler/lightningcss](lightningcss).
23  pub minify_css: bool,
24  /// Minify DOCTYPEs. Minified DOCTYPEs may not be spec compliant, but will still be parsed correctly by almost all browsers.
25  pub minify_doctype: bool,
26  /// Minify JavaScript in `<script>` tags using oxc.
27  pub minify_js: bool,
28  /// When `{{`, `{#`, or `{%` are seen in content, all source code until the subsequent matching closing `}}`, `#}`, or `%}` respectively gets piped through untouched.
29  pub preserve_brace_template_syntax: bool,
30  /// When `<%` is seen in content, all source code until the subsequent matching closing `%>` gets piped through untouched.
31  pub preserve_chevron_percent_template_syntax: bool,
32  /// Preserve self-closing syntax on unknown HTML elements (e.g. `<custom />`).
33  pub preserve_self_closing_on_unknown_tags: 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 enable_possibly_noncompliant(&mut self) {
46    self.allow_noncompliant_unquoted_attribute_values = true;
47    self.allow_optimal_entities = true;
48    self.allow_removing_spaces_between_attributes = true;
49    self.minify_doctype = true;
50  }
51}