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 CssFormatter

Remarks

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

NameDescription
CssFormatter()

CssFormatter()

protected CssFormatter()

No documentation is available.

Properties

NameDescription
DefaultThe 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.

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.

public static CssFormatter Default { get; }

Property value

CssFormatter

Methods

NameDescription
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)

Parameters

output TextWriter

Returns

CssWriter

Format overloads

Format(CssRule)

CssFormatter.cs

Returns the text of rule (see CssWriter.Write).

public string Format(CssRule rule)
Parameters
rule CssRule
Returns

string

Format(CssRule, TextWriter)

CssFormatter.cs

Writes the text of rule to output (see CssWriter.Write).

public void Format(CssRule rule, TextWriter output)
Parameters
rule CssRule
output TextWriter

Format(CssStyleDeclaration)

CssFormatter.cs

Returns the text of the declarations of declarations (see CssWriter.Write).

public string Format(CssStyleDeclaration declarations)
Parameters
declarations CssStyleDeclaration
Returns

string

Format(CssStyleDeclaration, TextWriter)

CssFormatter.cs

Writes the text of the declarations of declarations to output (see CssWriter.Write).

public void Format(CssStyleDeclaration declarations, TextWriter output)
Parameters
declarations CssStyleDeclaration
output TextWriter

Format(CssStyleSheet)

CssFormatter.cs

Returns the text of the rules of styleSheet (see CssWriter.Write).

public string Format(CssStyleSheet styleSheet)
Parameters
styleSheet CssStyleSheet
Returns

string

Format(CssStyleSheet, TextWriter)

CssFormatter.cs

Writes the text of the rules of styleSheet to output (see CssWriter.Write).

public void Format(CssStyleSheet styleSheet, TextWriter output)
Parameters
styleSheet CssStyleSheet
output TextWriter