YamlFormatter
OfficeIMO.Yaml
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
public static string Format(string yaml, YamlFormatOptions? options = null, YamlLoadOptions? loadOptions = null) #Formats YAML text.
Parameters
- yaml string
- The text to format.
- options OfficeIMO.Yaml.YamlFormatOptions? = null
- The layout, or null to keep the document's own conventions.
- loadOptions OfficeIMO.Yaml.YamlLoadOptions? = null
- 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
- The document to format.
- options OfficeIMO.Yaml.YamlFormatOptions?
- 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.