Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

YamlFormatter

OfficeIMO.Yaml

Namespace
OfficeIMO.Yaml
Assembly
OfficeIMO.Yaml
Source revision
ba882f6b0d07 with working tree changes
Modifiers
static

Rewrites YAML in one consistent layout. It writes the document through the same emitter as YamlSaveOptions.Reformat, 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. To repair individual problems while keeping every other line as it is, use YamlLinter.Fix instead.

Methods

Format 2 overloads
public static string Format(string yaml, YamlFormatOptions? options = null, YamlLoadOptions? loadOptions = null) #

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. Unity reads only the layout it writes, so its files are repaired with YamlLinter.Fix, which changes only the affected lines.
public static string Format(YamlDocument document, YamlFormatOptions? options) #

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. Unity reads only the layout it writes, so its files are repaired with YamlLinter.Fix, which changes only the affected lines.