Skip to content

Commit

Permalink
Merge pull request #519 from grishat/document-to-html
Browse files Browse the repository at this point in the history
ADD: Markdown.ToHtml from MarkdownDocument
  • Loading branch information
xoofx committed Mar 9, 2021
2 parents 9e5d30c + 4324caa commit 64ebff4
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Markdig/Markdown.cs
Expand Up @@ -88,6 +88,28 @@ public static string ToHtml(string markdown, MarkdownPipeline? pipeline = null,
return html;
}

/// <summary>
/// Converts a Markdown document to HTML.
/// </summary>
/// <param name="document">A Markdown document.</param>
/// <param name="pipeline">The pipeline used for the conversion.</param>
/// <returns>The result of the conversion</returns>
/// <exception cref="ArgumentNullException">if markdown document variable is null</exception>
public static string ToHtml(this MarkdownDocument document, MarkdownPipeline pipeline = null)
{
if (document == null) ThrowHelper.ArgumentNullException(nameof(document));
pipeline ??= new MarkdownPipelineBuilder().Build();

var renderer = pipeline.GetCacheableHtmlRenderer();

renderer.Render(document);
renderer.Writer.Flush();

string html = renderer.Writer.ToString();
pipeline.ReleaseCacheableHtmlRenderer(renderer);
return html;
}

/// <summary>
/// Converts a Markdown string to HTML and output to the specified writer.
/// </summary>
Expand Down Expand Up @@ -227,4 +249,4 @@ public static string ToPlainText(string markdown, MarkdownPipeline? pipeline = n
return writer.ToString();
}
}
}
}

0 comments on commit 64ebff4

Please sign in to comment.