# YamlFormatter

Rewrites YAML in one consistent layout.

Class 

`OfficeIMO.Yaml`

**Namespace**

`OfficeIMO.Yaml`

**Assembly**

`OfficeIMO.Yaml`

**Source revision**

`ba882f6b0d07` with working tree changes

**Source**

[YamlFormatter.cs:25](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Yaml/Lint/YamlFormatter.cs#L25)

**Modifiers**

static

Rewrites YAML in one consistent layout. It writes the document through the same emitter as [YamlSaveOptions.Reformat](/api/yaml/officeimo-yaml-yamlsaveoptions/), so values, scalar spellings, anchors, aliases, tags, comments and the blank lines above entries are kept, and formatting formatted text returns it unchanged.

## Inheritance

- object
- YamlFormatter

## Remarks

The layout is the emitter's: block collections indented by the configured widths, flow collections on one line, multi-line plain and folded scalars laid out again. Comments inside flow collections are dropped, as with [YamlSaveOptions.Reformat](/api/yaml/officeimo-yaml-yamlsaveoptions/). To repair individual problems while keeping every other line as it is, use [YamlLinter.Fix](/api/yaml/officeimo-yaml-yamllinter/) instead.

Filter members 

Show inherited

## Methods

Format 2 overloads

`public static string Format(string yaml, YamlFormatOptions? options = null, YamlLoadOptions? loadOptions = null)` [#](#method-format-string-officeimo-yaml-yamlformatoptions-officeimo-yaml-yamlloadoptions)

[YamlFormatter.cs:25](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Yaml/Lint/YamlFormatter.cs#L25)

Formats YAML text.

Parameters

**yaml string required**

The text to format.

**options OfficeIMO.Yaml.YamlFormatOptions? = null optional**

The layout, or null to keep the document's own conventions.

**loadOptions OfficeIMO.Yaml.YamlLoadOptions? = null optional**

How the text is loaded, or null for the defaults.

Returns

`string` The formatted text.

Exceptions

- `YamlException` – The text is not valid YAML.
- `NotSupportedException` – The document was loaded with [YamlDialect.Unity](/api/yaml/officeimo-yaml-yamldialect/). Unity reads only the layout it writes, so its files are repaired with [YamlLinter.Fix](/api/yaml/officeimo-yaml-yamllinter/), which changes only the affected lines.

`public static string Format(YamlDocument document, YamlFormatOptions? options)` [#](#method-format-officeimo-yaml-yamldocument-officeimo-yaml-yamlformatoptions)

[YamlFormatter.cs:37](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Yaml/Lint/YamlFormatter.cs#L37)

Formats a document, including any edits made to it, without changing the document.

Parameters

**document OfficeIMO.Yaml.YamlDocument required**

The document to format.

**options OfficeIMO.Yaml.YamlFormatOptions? required**

The layout, or null to keep the document's own conventions.

Returns

`string` The formatted text.

Exceptions

- `NotSupportedException` – The document was loaded with [YamlDialect.Unity](/api/yaml/officeimo-yaml-yamldialect/). Unity reads only the layout it writes, so its files are repaired with [YamlLinter.Fix](/api/yaml/officeimo-yaml-yamllinter/), which changes only the affected lines.

## Inherited Methods

`public virtual bool Equals(object? obj)` [#](#method-equals-object)

Inherited from object

Parameters

**obj object? required**

Returns

`bool`

`public virtual int GetHashCode()` [#](#method-gethashcode)

Inherited from object

Returns

`int`

`public Type GetType()` [#](#method-gettype)

Inherited from object

Returns

`Type`

`public virtual string? ToString()` [#](#method-tostring)

Inherited from object

Returns

`string?`

<!-- PowerForge markdown artifact sha256:C0A0A9E209E2677BA205AE5D2C144C2D39CE533487DACCF83C0AE57717E189B2 -->
