Table of Contents

Interface IMarkdownEditor

Namespace
DocToolkit.Extensions.DependencyInjection
Assembly
DocToolkit.Extensions.DependencyInjection.dll

Reads and updates an existing Markdown document — front matter, headings, tables, and one section's content — without converting to another format first. Registered by AddDocToolkit(IServiceCollection, Action<DocToolkitOptions>?).

public interface IMarkdownEditor

Remarks

No Stream or async overload on any method here, matching the static API: the input is a string rather than a document, and every method is CPU-bound rather than genuinely I/O-bound. See MarkdownEditor's own remarks.

Methods

FindHeading(string, string, StringComparison)

The heading in markdown whose text matches headingText, or null if none does. When more than one heading shares the same text, the first one in document order is returned.

MarkdownHeading? FindHeading(string markdown, string headingText, StringComparison comparison = StringComparison.OrdinalIgnoreCase)

Parameters

markdown string
headingText string
comparison StringComparison

Returns

MarkdownHeading

Exceptions

ArgumentNullException

markdown or headingText is null.

DocumentConversionException

The Markdown could not be parsed.

ReadFrontMatter(string)

Every front-matter key in markdown, with its parsed value. A document with no front matter returns an empty dictionary, never null.

IReadOnlyDictionary<string, object> ReadFrontMatter(string markdown)

Parameters

markdown string

Returns

IReadOnlyDictionary<string, object>

Exceptions

ArgumentNullException

markdown is null.

DocumentConversionException

The Markdown could not be parsed.

ReadTable(string, int)

The table at index, as rows of cell text — the header row is row 0, followed by every data row in document order.

IReadOnlyList<IReadOnlyList<string>> ReadTable(string markdown, int index)

Parameters

markdown string
index int

Returns

IReadOnlyList<IReadOnlyList<string>>

Exceptions

ArgumentNullException

markdown is null.

ArgumentOutOfRangeException

index is negative, or at or beyond TableCount(string).

DocumentConversionException

The Markdown could not be parsed.

ReplaceSection(string, string, string, StringComparison)

Replaces the content of the section under the heading matching headingText with newContent, and returns the whole updated document. Front matter and every other section are left untouched.

string ReplaceSection(string markdown, string headingText, string newContent, StringComparison comparison = StringComparison.OrdinalIgnoreCase)

Parameters

markdown string
headingText string
newContent string
comparison StringComparison

Returns

string

Exceptions

ArgumentNullException

Any argument is null.

ArgumentException

No top-level heading matches headingText.

DocumentConversionException

The Markdown could not be parsed.

TableCount(string)

The number of tables in markdown, in document order.

int TableCount(string markdown)

Parameters

markdown string

Returns

int

Exceptions

ArgumentNullException

markdown is null.

DocumentConversionException

The Markdown could not be parsed.