HtmlLoadOptions.BlockImportMode

HtmlLoadOptions BlockImportMode property. Gets or sets a value that specifies how properties of blocklevel elements are imported. Default value is Merge.

HtmlLoadOptions.BlockImportMode property

Gets or sets a value that specifies how properties of block-level elements are imported. Default value is Merge.

public BlockImportMode BlockImportMode { get; set; }

Examples

Shows how properties of block-level elements are imported from HTML-based documents.

const string html = @"
    <html>
        <div style='border:dotted'>
            <div style='border:solid'>
                <p>paragraph 1</p>
                <p>paragraph 2</p>
            </div>
        </div>
    </html>";
MemoryStream htmlStream = new MemoryStream(Encoding.UTF8.GetBytes(html));

HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();
// By default, properties of parent blocks are merged and stored on child elements (i.e. paragraphs or tables).
// Change the behavior to preserve block level elements as a special logical structure in the output document.
htmlLoadOptions.BlockImportMode = BlockImportMode.Preserve;

Converter.Create()
    .From(htmlStream, htmlLoadOptions)
    .To(ArtifactsDir + "HtmlLoadOptions.BlockImportMode.docx")
    .Execute();

See Also