Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

FrontMatterBlock

OfficeIMO.Markdown

Namespace
OfficeIMO.Markdown
Assembly
OfficeIMO.Markdown
Source revision
9931e96ab849 with working tree changes
Implements
IFrontMatterMarkdownBlock IMarkdownBlock ISyntaxMarkdownBlock
Modifiers
sealed

YAML front matter at the start of a document, read and written by OfficeIMO.Yaml. FrontMatterBlock.Yaml holds the lossless document: nested values are reachable through it, edits made to it are saved with only the changed text rewritten, and an unedited block renders back to the bytes it was read from.

Inheritance

Usage

Explore 4 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Methods

public Entry? FindEntry(string key, StringComparison comparison = OrdinalIgnoreCase) #

Finds a top-level entry by key. When keys repeat under the comparison, the last one wins, as it does for YAML loaders that accept repeated keys.

Parameters

key string required
comparison System.StringComparison = OrdinalIgnoreCase optional

Returns

Entry?
public static FrontMatterBlock FromObject(object data) #

Creates front matter from an anonymous object, a dictionary or another object's public properties. Nested dictionaries, objects and collections become YAML mappings and sequences, and YamlNode values are used as they are.

Parameters

data object required
public static FrontMatterBlock FromObject<T>(T? data) #

Creates front matter from a typed object's public properties or from a dictionary. Nested dictionaries and collections become YAML mappings and sequences; other nested objects are written as their invariant text.

Type Parameters

T

Parameters

data T? required
public bool HasEntry(string key, StringComparison comparison = OrdinalIgnoreCase) #

Checks whether the front matter has a top-level entry with the key.

Parameters

key string required
comparison System.StringComparison = OrdinalIgnoreCase optional

Returns

bool
public string Render() #

Renders the front matter with its fences. Unedited front matter read from Markdown renders the text it was read from; edits made through FrontMatterBlock.Yaml rewrite only what changed.

Returns

string
public YamlNode? Select(string path) #

Returns the node a YAML path such as author.name or tags[0] addresses, or null.

Parameters

path string required

Returns

YamlNode?
public bool TryGetValue<T>(string key, out T? value) #

Reads a top-level scalar entry as T through the YAML schema, as YamlNode.TryGetValue does: string, bool, int, long, double, float, decimal and their nullable forms. Returns false when the key is missing, the value is a collection or it does not convert.

Type Parameters

T

Parameters

key string required
value T? required

Returns

bool

Exceptions

  • NotSupportedException – T is not a supported type.

Properties

public YamlDocument? Yaml { get; } #

Gets the YAML document, or null when the text between the fences is not valid YAML; then FrontMatterBlock.Diagnostics holds the error and the block renders FrontMatterBlock.RawYaml unchanged.

public YamlMapping? Mapping { get; } #

Gets the root mapping of the front matter, or null when it is empty, invalid or not a mapping.

public IReadOnlyList<Entry> Entries { get; } #

Gets the top-level entries of FrontMatterBlock.Mapping in source order, with Markdown source spans for entries that were read from Markdown. The list follows edits made through FrontMatterBlock.Yaml.

public string? RawYaml { get; } #

Gets the text between the fences as it was read from Markdown, or null for front matter built in code.

public MarkdownSourceSpan? BodySourceSpan { get; } #

Gets the source span of the text between the fences when parsed from Markdown.

public IReadOnlyList<OfficeDiagnostic> Diagnostics { get; } #

Gets findings from reading the front matter: a OfficeDiagnosticCodes.MarkdownFrontMatterInvalidYaml error located in the Markdown source when the YAML is invalid, and otherwise the YAML document's own findings, such as repeated keys, located within the front matter text.