Class DocxToMarkdownConverter
- Namespace
- DocToolkit
- Assembly
- DocToolkit.dll
Converts a Word (.docx) package to Markdown, keeping the structure
ExtractText(byte[]) throws away: a heading becomes #, a table
becomes a pipe table. Use ExtractText when flat text is what you want.
The result is self-contained. Images in the source document are embedded as
data: URIs rather than written beside the output and referenced by path, so the string
this returns stands on its own.
public static class DocxToMarkdownConverter
- Inheritance
-
DocxToMarkdownConverter
- Inherited Members
Methods
Convert(byte[])
Converts the .docx in docx to Markdown.
public static string Convert(byte[] docx)
Parameters
docxbyte[]The document to convert.
Returns
Examples
// Structure survives: a heading becomes "#", a table becomes a pipe table. ExtractText, by
// contrast, returns the same words as flat lines with no markup at all.
string markdown = DocxToMarkdownConverter.Convert(docx);
Exceptions
- ArgumentNullException
docxis null.- ArgumentException
docxis empty.- DocumentConversionException
The document could not be converted.
ConvertAsync(Stream, CancellationToken)
Reads a .docx from source and returns it as Markdown.
source is read to its end and is not disposed, closed or sought, so
it may be forward-only — an HTTP request body, for instance.
public static Task<string> ConvertAsync(Stream source, CancellationToken ct = default)
Parameters
sourceStreamThe stream the .docx package is read from.
ctCancellationTokenCancels the read.
Returns
Exceptions
- ArgumentNullException
sourceis null.- ArgumentException
sourceis not readable or held no bytes.- OperationCanceledException
ctwas cancelled.- DocumentConversionException
The document could not be converted.