CssFormatter Class
Converts a style sheet, a rule or a declaration block to CSS text. CssFormatter.Default uses the CSSOM serialization (https://drafts.csswg.org/cssom/#serialize-a-css-rule); CssMinifyFormatter and CssPrettyFormatter produce a minified or an indented output.
public abstract class CssFormatterRemarks
The object model is formatted, not the text it was parsed from: as in the browsers, the comments, the invalid rules and the declarations of unsupported properties are not in the object model, and the values are written in their serialized form (e.g. #f00 is written rgb(255, 0, 0)).
A formatter is immutable and can be used concurrently: each call creates a CssWriter that holds the state of the conversion. To customize the output, derive from CssWriter and return it from CssFormatter.CreateWriter.
Constructors
| Name | Description |
|---|---|
| CssFormatter() |
CssFormatter()
protected CssFormatter()No documentation is available.
Properties
| Name | Description |
|---|---|
| Default | The formatter that uses the CSSOM serialization: the output is the same as CssRule.CssText and CssStyleDeclaration.CssText; the rules of a style sheet are separated by a line feed. |
Default
CssFormatter.csThe formatter that uses the CSSOM serialization: the output is the same as CssRule.CssText and CssStyleDeclaration.CssText; the rules of a style sheet are separated by a line feed.
public static CssFormatter Default { get; }Property value
Methods
| Name | Description |
|---|---|
| CreateWriter(TextWriter) | Creates the writer that converts one style sheet, rule or declaration block to text. |
| Format(CssRule) | Returns the text of rule (see CssWriter.Write). |
| Format(CssRule, TextWriter) | Writes the text of rule to output (see CssWriter.Write). |
| Format(CssStyleDeclaration) | Returns the text of the declarations of declarations (see CssWriter.Write). |
| Format(CssStyleDeclaration, TextWriter) | Writes the text of the declarations of declarations to output (see CssWriter.Write). |
| Format(CssStyleSheet) | Returns the text of the rules of styleSheet (see CssWriter.Write). |
| Format(CssStyleSheet, TextWriter) | Writes the text of the rules of styleSheet to output (see CssWriter.Write). |
CreateWriter(TextWriter)
Creates the writer that converts one style sheet, rule or declaration block to text.
protected abstract CssWriter CreateWriter(TextWriter output)Format overloads
Format(CssRule)
CssFormatter.csReturns the text of rule (see CssWriter.Write).
Format(CssRule, TextWriter)
CssFormatter.csWrites the text of rule to output (see CssWriter.Write).
public void Format(CssRule rule, TextWriter output)Parameters
ruleCssRuleoutputTextWriter
Format(CssStyleDeclaration)
CssFormatter.csReturns the text of the declarations of declarations (see CssWriter.Write).
public string Format(CssStyleDeclaration declarations)Format(CssStyleDeclaration, TextWriter)
CssFormatter.csWrites the text of the declarations of declarations to output (see CssWriter.Write).
public void Format(CssStyleDeclaration declarations, TextWriter output)Parameters
declarationsCssStyleDeclarationoutputTextWriter
Format(CssStyleSheet)
CssFormatter.csReturns the text of the rules of styleSheet (see CssWriter.Write).
public string Format(CssStyleSheet styleSheet)Format(CssStyleSheet, TextWriter)
CssFormatter.csWrites the text of the rules of styleSheet to output (see CssWriter.Write).
public void Format(CssStyleSheet styleSheet, TextWriter output)Parameters
styleSheetCssStyleSheetoutputTextWriter