HtmlMinifyFormatter Class
Writes a minified HTML markup: the comments, the collapsible whitespace, the optional tags and the unneeded attribute quotes are removed, and only the characters that must be escaped are escaped. The document is not modified.
public sealed class HtmlMinifyFormatter : HtmlFormatterRemarks
Only the HTML is minified: the content of the script elements is written as is, and so are the content of the style elements and the value of the style attributes, unless HtmlFormatter.StyleElementFormatter or HtmlFormatter.StyleAttributeFormatter is set (e.g. to a CssMinifyFormatter).
The whitespace that is removed is determined from the computed styles of the elements (display, white-space-collapse and the content of the ::before and ::after pseudo-elements), computed from the user agent style sheet and the style sheets of the document. Every media query is considered to match, so the whitespace that is significant in any environment (screen size, print, color scheme...) is kept.
- Inheritance
HtmlFormatterHtmlMinifyFormatter
Constructors
| Name | Description |
|---|---|
| HtmlMinifyFormatter() |
HtmlMinifyFormatter()
HtmlMinifyFormatter.cspublic HtmlMinifyFormatter()No documentation is available.
Properties
| Name | Description |
|---|---|
| CollapseWhitespace | Whether the collapsible whitespace is collapsed: a sequence of ASCII whitespace is replaced by a single space, and the spaces that are not rendered (at the start or the end of a line, or following another space) are removed. The text whose whitespace is preserved (e.g. in pre or textarea) is not modified, and the whitespace of the class attributes is collapsed. The default is true. |
| OmitOptionalTags | Whether the start and end tags that can be omitted without changing the document are omitted (https://html.spec.whatwg.org/multipage/syntax.html#optional-tags). The default is true. |
| PreservedStartTags | The local names of the HTML elements whose start tag is always written, even when it can be omitted (e.g. html and head, for the tools that expect them). The names are compared ASCII case-insensitively. Empty by default. |
| RemoveAttributeQuotes | Whether the quotes of the attribute values are removed when the value does not need them, a single quote is used when it avoids escaping double quotes, and the empty values are omitted (<script defer>). The default is true. |
| RemoveComments | Whether the comments are removed. The default is true. |
| RemoveScriptTypeAttribute | Whether the type attribute of the script elements is removed when it denotes a classic script (an empty value or a JavaScript MIME type such as text/javascript). The default is true. |
| TrimTrailingWhitespaceInPreformattedText | Whether the spaces and tabs at the end of the lines of the preformatted text (white-space-collapse: preserve, e.g. in pre) are removed, as well as the trailing whitespace of the preformatted elements. The default is true. |
CollapseWhitespace
HtmlMinifyFormatter.csWhether the collapsible whitespace is collapsed: a sequence of ASCII whitespace is replaced by a single space, and the spaces that are not rendered (at the start or the end of a line, or following another space) are removed. The text whose whitespace is preserved (e.g. in pre or textarea) is not modified, and the whitespace of the class attributes is collapsed. The default is true.
public bool CollapseWhitespace { get; init; }Property value
OmitOptionalTags
HtmlMinifyFormatter.csPreservedStartTags
HtmlMinifyFormatter.csThe local names of the HTML elements whose start tag is always written, even when it can be omitted (e.g. html and head, for the tools that expect them). The names are compared ASCII case-insensitively. Empty by default.
public IReadOnlyCollection<string> PreservedStartTags { get; init; }Property value
RemoveAttributeQuotes
HtmlMinifyFormatter.csRemoveComments
HtmlMinifyFormatter.csRemoveScriptTypeAttribute
HtmlMinifyFormatter.csTrimTrailingWhitespaceInPreformattedText
HtmlMinifyFormatter.csWhether the spaces and tabs at the end of the lines of the preformatted text (white-space-collapse: preserve, e.g. in pre) are removed, as well as the trailing whitespace of the preformatted elements. The default is true.
public bool TrimTrailingWhitespaceInPreformattedText { get; init; }