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
markdownstringThe Markdown to convert.
Returns
- byte[]
Exceptions
- ArgumentNullException
markdownis 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
markdownstringThe Markdown to convert.
destinationStreamThe stream the .docx package is written to.
ctCancellationTokenCancels the write.
Returns
Exceptions
- ArgumentNullException
Either argument is null.
- ArgumentException
destinationis not writable.- OperationCanceledException
ctwas 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
markdownstringThe Markdown to convert.
Returns
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
markdownis null.- DocumentConversionException
The Markdown could not be converted.