Table of Contents

Class MarkdownToDocxConverter

Namespace
DocToolkit
Assembly
DocToolkit.dll

Converts Markdown to a Word (.docx) package, completing the round trip DocxToMarkdownConverter opened: a # becomes a heading, a pipe table becomes a table.

public static class MarkdownToDocxConverter
Inheritance
MarkdownToDocxConverter
Inherited Members

Remarks

Nothing here reaches the network or the disk. A remote image reference becomes a hyperlink rather than a fetch, and a local file reference is refused — reading a path out of untrusted document content would let the document choose which file gets embedded in the output. data: images are inlined, since they carry their own bytes. See DocToolkit.MarkdownImportOptions, which sets each of those explicitly rather than inheriting it.

No Stream source overload. The input is a string rather than a document, so a caller holding bytes decides their own encoding — the same reason HtmlToDocxConverter has none.

Methods

Convert(string)

Converts markdown to a .docx package.

public static byte[] Convert(string markdown)

Parameters

markdown string

The Markdown to convert.

Returns

byte[]

Exceptions

ArgumentNullException

markdown is null.

DocumentConversionException

The Markdown could not be converted.

ConvertAsync(string, Stream, CancellationToken)

Converts markdown and writes the .docx package to destination.

destination is written and is neither disposed, closed nor sought, so it may be forward-only — an HTTP response body, for instance.

public static Task ConvertAsync(string markdown, Stream destination, CancellationToken ct = default)

Parameters

markdown string

The Markdown to convert.

destination Stream

The stream the .docx package is written to.

ct CancellationToken

Cancels the write.

Returns

Task

Exceptions

ArgumentNullException

Either argument is null.

ArgumentException

destination is not writable.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The Markdown could not be converted.

ConvertWithReport(string)

Converts markdown to a .docx package, and reports what the conversion could not carry across.

public static ConversionResult<byte[]> ConvertWithReport(string markdown)

Parameters

markdown string

The Markdown to convert.

Returns

ConversionResult<byte[]>

Remarks

Convert(string) produces the same document and is unchanged; this overload is opt-in. Markdown and DOCX do not express the same set of things, so a conversion between them can legitimately drop or approximate content — and the underlying converter reports that rather than leaving it to be discovered.

The result is always usable: this reports loss, it does not refuse.

Exceptions

ArgumentNullException

markdown is null.

DocumentConversionException

The Markdown could not be converted.