From 0794213eefbc97a51c00e0db8a1d60f45368229e Mon Sep 17 00:00:00 2001 From: Yufei Huang Date: Tue, 10 Jul 2018 11:52:32 +0800 Subject: [PATCH] Make AutoIdentifierExtension thread safe --- .../AutoIdentifierExtension.cs | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Markdig/Extensions/AutoIdentifiers/AutoIdentifierExtension.cs b/src/Markdig/Extensions/AutoIdentifiers/AutoIdentifierExtension.cs index 7fc79131..379b0733 100644 --- a/src/Markdig/Extensions/AutoIdentifiers/AutoIdentifierExtension.cs +++ b/src/Markdig/Extensions/AutoIdentifiers/AutoIdentifierExtension.cs @@ -21,8 +21,6 @@ namespace Markdig.Extensions.AutoIdentifiers public class AutoIdentifierExtension : IMarkdownExtension { private const string AutoIdentifierKey = "AutoIdentifier"; - private readonly HtmlRenderer stripRenderer; - private readonly StringWriter headingWriter; private readonly AutoIdentifierOptions options; /// @@ -32,14 +30,6 @@ namespace Markdig.Extensions.AutoIdentifiers public AutoIdentifierExtension(AutoIdentifierOptions options) { this.options = options; - headingWriter = new StringWriter(); - // Use internally a HtmlRenderer to strip links from a heading - stripRenderer = new HtmlRenderer(headingWriter) - { - // Set to false both to avoid having any HTML tags in the output - EnableHtmlForInline = false, - EnableHtmlEscape = false - }; } public void Setup(MarkdownPipelineBuilder pipeline) @@ -166,9 +156,17 @@ namespace Markdig.Extensions.AutoIdentifiers if (attributes.Id != null) { return; - } + } + + // Use internally a HtmlRenderer to strip links from a heading + var headingWriter = new StringWriter(); + var stripRenderer = new HtmlRenderer(headingWriter) + { + // Set to false both to avoid having any HTML tags in the output + EnableHtmlForInline = false, + EnableHtmlEscape = false + }; - // Use a HtmlRenderer with stripRenderer.Render(headingBlock.Inline); var headingText = headingWriter.ToString(); headingWriter.GetStringBuilder().Length = 0;