Structured Document API

To parse a document, simply pass the raw text into the constructor.

var doc = new StructuredText("the entire text of the document");

The document will parse, and populate all its properties.

Section Collections

The primary feature of the document are lists of Section objects, in several collections:

There are methods for working with sections:

Content

Each section has a Content property that contains whatever is separated from the meta by a blank line.

Each section also exposes a Lines property which is a list of strings representing each line in the section. TrimmedLines removes the blank lines from the beginning and end of the content (but retains any blank lines in the middle).

Metadata Collections

Each section – and the document as a whole – has a MetaCollection object exposed at the Meta property. It exposes the following methods:

Document Meta

The document as a whole – like each of its sections – exposes a Meta property which functions as above. This meta collection is simply the same meta collection of the first section.

However, the document also exposes an AllMeta property which is a consolidated list of all the meta items from all the sections in the document.

Many of the meta-related methods return the first meta value found for the key, which means AllMeta can be used to search down through multiple sections for a specific meta key.

Meta also has a few convenience properties for common meta.

Example

Consider this document:

title: The Barker Family
established: 1999-06-05

\[[ person ]]
first: Deane
last: Barker

The husband

\[[ person ]]
first: Annie
last: Barker

The wife

We can work with it like this:

var doc = new StructuredText(documentText);

Console.WriteLine(doc.Title);
Console.WriteLine($"Est. {doc.Get<DateTime>("established"):MMMM, d yyyy}");

foreach(var section in doc.GetSections("person"))
{
    var lastName = section.Meta.Get("last");
    var firstName = section.Meta.Get("first")
    Console.WriteLine($"{last}, {first}: {section.Content}");
}

Resulting in:

The Barker Family
Est. June 5, 1999
Barker, Deane: The husband
Barker, Annie: The wife

SectionMap

Each section has a Map property which exposes numerous properties regarding where that section lies in context of the entire document.

This is item #2 in a sequence of 4 items.

You can use your left/right arrow keys to navigate