IDocumentFormatter.CreateMarkupWriter Method

Namespace
Kampute.DocToolkit.Formatters
Assembly
  • Kampute.DocToolkit.dll

Definition

Creates an instance of MarkupWriter class that wraps the specified writer for encoding content in the target format.
MarkupWriter CreateMarkupWriter(TextWriter writer, bool disposeWriter = false)

Parameters

writer TextWriter
The TextWriter to write the encoded content to.
disposeWriter bool optional
true if the wrapped writer should be disposed when the returned MarkupWriter is disposed; otherwise, false. The default is false.

Returns

MarkupWriter
A new instance of a MarkupWriter object that wraps the specified writer.

Remarks

The returned MarkupWriter instance provides a rich API for writing structured content with proper encoding for the target format. It handles format-specific escaping, semantic document elements (headings, lists, tables, etc.), and cross-references.
It is the caller's responsibility to dispose the returned MarkupWriter instance to release any resources.

Examples

Here is an example of how to use the IDocumentFormatter.CreateMarkupWriter(TextWriter, bool) method:
using var markupWriter = formatter.CreateMarkupWriter(textWriter);
markupWriter.WriteHeading("Title", 1);
markupWriter.WriteParagraph("This is properly encoded content for the target format.");