Table of Contents

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

docx byte[]

The document to convert.

Returns

string

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

docx is null.

ArgumentException

docx is 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

source Stream

The stream the .docx package is read from.

ct CancellationToken

Cancels the read.

Returns

Task<string>

Exceptions

ArgumentNullException

source is null.

ArgumentException

source is not readable or held no bytes.

OperationCanceledException

ct was cancelled.

DocumentConversionException

The document could not be converted.