FrontMatterBlock
OfficeIMO.Markdown
Front matter at the start of a document: YAML between --- fences, read and written by OfficeIMO.Yaml, or TOML between +++ fences, read and written by OfficeIMO.Toml. FrontMatterBlock.Yaml or FrontMatterBlock.Toml holds the lossless document: 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. FrontMatterBlock.Entries, FrontMatterBlock.Select and FrontMatterBlock.TryGetValue read both formats the same way.
Inheritance
- MarkdownObject
- MarkdownBlock
- FrontMatterBlock
Usage
Explore 5 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.
Returned or exposed by 5
- Method FrontMatterBlock.FromObject
- Method FrontMatterBlock.FromObject``1
- Method FrontMatterBlock.FromToml
- Property MarkdownDocument.DocumentHeader
- Property MarkdownNativeFrontMatterBlock.FrontMatter
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
- comparison System.StringComparison = OrdinalIgnoreCase
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
Returns
FrontMatterBlockpublic 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?
Returns
FrontMatterBlockpublic static FrontMatterBlock FromToml(TomlDocument document) #Creates TOML front matter, written between +++ fences, from a TOML document. The block keeps the document, so edits made to it later are part of the rendered front matter.
Parameters
- document OfficeIMO.Toml.TomlDocument
Returns
FrontMatterBlockpublic bool HasEntry(string key, StringComparison comparison = OrdinalIgnoreCase) #Checks whether the front matter has a top-level entry with the key.
Parameters
- key string
- comparison System.StringComparison = OrdinalIgnoreCase
Returns
boolpublic 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 or FrontMatterBlock.Toml rewrite only what changed.
Returns
stringpublic YamlNode? Select(string path) #Returns the node a path such as author.name or tags[0] addresses, or null.
Parameters
- path string
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
- value T?
Returns
boolExceptions
NotSupportedException– T is not a supported type.
Inherited Methods
public void Accept(MarkdownVisitor visitor) #Parameters
- visitor MarkdownVisitor
public IEnumerable<MarkdownObject> Ancestors() #Returns
IEnumerable<MarkdownObject>public IEnumerable<MarkdownObject> AncestorsAndSelf() #Returns
IEnumerable<MarkdownObject>public IEnumerable<TObject> DescendantObjectsOfType<TObject>() #Type Parameters
- TObject
Returns
IEnumerable<TObject>public IEnumerable<MarkdownObject> Descendants() #Returns
IEnumerable<MarkdownObject>Properties
public MarkdownFrontMatterFormat Format { get; } #Gets the front matter language: YAML between --- fences or TOML between +++ fences.
public YamlDocument? Yaml { get; } #Gets the YAML document of YAML front matter, or null for TOML front matter and when the text between the fences is not valid YAML; then FrontMatterBlock.Diagnostics holds the error and the block renders FrontMatterBlock.RawText unchanged.
public TomlDocument? Toml { get; } #Gets the TOML document of TOML front matter, or null for YAML front matter and when the text between the fences is not valid TOML; then FrontMatterBlock.Diagnostics holds the error and the block renders FrontMatterBlock.RawText unchanged.
public YamlMapping? Mapping { get; } #Gets the root mapping of the front matter, or null when it is empty, invalid or not a mapping. For TOML front matter it is a read-only view of the root table that follows edits made through FrontMatterBlock.Toml.
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 or FrontMatterBlock.Toml.
public string? RawText { 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 or OfficeDiagnosticCodes.MarkdownFrontMatterInvalidToml error located in the Markdown source when the text is invalid, and otherwise the YAML document's own findings, such as repeated keys, located within the front matter text. Valid TOML has no findings.
Inherited Properties
public MarkdownSourceSpan? SourceSpan { get; internal set; } #public IReadOnlyList<MarkdownObject> ChildObjects { get; } #