Skip to content

Commit

Permalink
Cache the MarkdownParser & Processors
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Mar 12, 2021
1 parent 13bdab4 commit 82fdf99
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 272 deletions.
6 changes: 3 additions & 3 deletions src/Markdig/Markdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public static partial class Markdown
{
public static readonly string Version = ((AssemblyFileVersionAttribute) typeof(Markdown).Assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)[0]).Version;

private static readonly MarkdownPipeline _defaultPipeline = new MarkdownPipelineBuilder().Build();
internal static readonly MarkdownPipeline DefaultPipeline = new MarkdownPipelineBuilder().Build();
private static readonly MarkdownPipeline _defaultTrackTriviaPipeline = new MarkdownPipelineBuilder().EnableTrackTrivia().Build();

private static MarkdownPipeline GetPipeline(MarkdownPipeline? pipeline, string markdown)
{
if (pipeline is null)
{
return _defaultPipeline;
return DefaultPipeline;
}

var selfPipeline = pipeline.Extensions.Find<SelfPipelineExtension>();
Expand Down Expand Up @@ -111,7 +111,7 @@ public static string ToHtml(this MarkdownDocument document, MarkdownPipeline? pi
{
if (document is null) ThrowHelper.ArgumentNullException(nameof(document));

pipeline ??= _defaultPipeline;
pipeline ??= DefaultPipeline;

using var rentedRenderer = pipeline.RentHtmlRenderer();
HtmlRenderer renderer = rentedRenderer.Instance;
Expand Down
Loading

0 comments on commit 82fdf99

Please sign in to comment.