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
markdownstringheadingTextstringcomparisonStringComparison
Returns
Exceptions
- ArgumentNullException
markdownorheadingTextis 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
markdownstring
Returns
Exceptions
- ArgumentNullException
markdownis 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
Returns
Exceptions
- ArgumentNullException
markdownis null.- ArgumentOutOfRangeException
indexis 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
markdownstringheadingTextstringnewContentstringcomparisonStringComparison
Returns
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
markdownstring
Returns
Exceptions
- ArgumentNullException
markdownis null.- DocumentConversionException
The Markdown could not be parsed.