alexa
menu

Blazor

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Search Results for

    Show / Hide Table of Contents

    Class SfMarkdownConverter

    Provides a static utility for converting Markdown text to HTML.

    Inheritance
    object
    SfMarkdownConverter
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Syncfusion.Blazor.MarkdownConverter
    Assembly: Syncfusion.Blazor.dll
    Syntax
    public static class SfMarkdownConverter
    Remarks

    The converter is implemented entirely in C# with no JavaScript dependencies, ensuring full compatibility with Blazor Server and Blazor WebAssembly environments.

    It supports core CommonMark syntax and selected GitHub Flavored Markdown (GFM) extensions (tables, task lists, strikethrough, autolinks) when enabled through options.

    Examples
    // Create options with GFM enabled
    var options = new MarkdownConverterOptions
    {
        Gfm = true,
        LineBreak = true,
        Silent = false
    };
    
    // Use options with converter
    string html = SfMarkdownConverter.ToHtml(markdownContent, options);

    Methods

    ToHtml(string, MarkdownConverterOptions)

    Converts the provided Markdown text into HTML based on the given options.

    Declaration
    public static string ToHtml(string markdown, MarkdownConverterOptions options = null)
    Parameters
    Type Name Description
    string markdown

    The Markdown source content to parse. Null or empty inputs return an empty string.

    MarkdownConverterOptions options

    Optional configuration. If null, default options are used.

    Returns
    Type Description
    string

    A string containing the converted HTML output.

    Remarks

    This method performs synchronous conversion and is suitable for small to medium-sized documents (≤10 KB). Performance target: <10 ms.

    For large documents (>10 KB), use ToHtmlAsync(string, MarkdownConverterOptions) to prevent blocking the UI thread.

    The converter produces semantic, accessible HTML output and supports GFM extensions when Gfm is enabled (default: true).

    Examples
    // Basic synchronous usage
    string html = SfMarkdownConverter.ToHtml("# Hello Blazor");
    
    // With options
    var options = new MarkdownConverterOptions
    {
        Gfm = true,
        LineBreak = true,
        Silent = false
    };
    string result = SfMarkdownConverter.ToHtml(markdownText, options);

    ToHtmlAsync(string, MarkdownConverterOptions)

    Asynchronously converts the provided Markdown text into HTML based on the given options.

    Declaration
    public static Task<string> ToHtmlAsync(string markdown, MarkdownConverterOptions options = null)
    Parameters
    Type Name Description
    string markdown

    The Markdown source content to parse. Null or empty inputs return an empty string.

    MarkdownConverterOptions options

    Optional configuration. If null, default options are used.

    Returns
    Type Description
    Task<string>

    A task that resolves to the converted HTML string.

    Remarks

    Recommended for large documents to prevent UI thread blocking in Blazor WebAssembly or to offload work in Blazor Server. Performance target: <50 ms for ≤100 KB.

    In WebAssembly, processing is chunked using await Task.Yield() to maintain responsiveness.

    Examples
    string largeHtml = await SfMarkdownConverter.ToHtmlAsync(largeMarkdown);
    
    // With options
    var options = new MarkdownConverterOptions { Gfm = true };
    string result = await SfMarkdownConverter.ToHtmlAsync(markdownText, options);
    In this article
    Back to top Generated by DocFX
    Copyright © 2001 - 2026 Syncfusion Inc. All Rights Reserved