Multiple calls to Markdown.ToHtml with same pipeline parameter throws an exception #6

Closed
opened 2026-01-29 14:19:03 +00:00 by claunia · 2 comments
Owner

Originally created by @pekkah on GitHub (May 29, 2016).

When calling Render method of following class more than once Markdown.ToHtml throws an exception (at the bottom). It seems to be related to the _pipeline parameter. If I remove it from the parameters multiple calls work as expected.

Class:

 public class MarkdigRenderer : IMarkdownRenderer
    {
        private readonly MarkdownPipeline _pipeline;

        public MarkdigRenderer()
        {
            _pipeline = new MarkdownPipeline().UseAllExtensions();
            _pipeline.DebugLog = new StringWriter();
        }

        public string Render(string markdown)
        {
            var html =  Markdown.ToHtml(markdown, _pipeline);

            return html;
        }
    }

Exception

System.InvalidOperationException: The character `:` is already used by another emphasis descriptor
   at Markdig.Parsers.Inlines.EmphasisInlineParser.Initialize(InlineProcessor processor)
   at Markdig.Parsers.ParserList`2.Initialize(TState initState)
   at Markdig.Parsers.InlineParserList.Initialize(InlineProcessor initState)
   at Markdig.Parsers.InlineProcessor..ctor(StringBuilderCache stringBuilders, MarkdownDocument document, InlineParserList parsers)
   at Markdig.Parsers.MarkdownParser..ctor(TextReader reader, MarkdownPipeline pipeline)
   at Markdig.Parsers.MarkdownParser.Parse(TextReader reader, MarkdownPipeline pipeline)
   at Markdig.Markdown.ToHtml(TextReader reader, TextWriter writer, MarkdownPipeline pipeline)
   at Markdig.Markdown.ToHtml(TextReader reader, MarkdownPipeline pipeline)
   at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline)
Originally created by @pekkah on GitHub (May 29, 2016). When calling Render method of following class more than once `Markdown.ToHtml` throws an exception (at the bottom). It seems to be related to the `_pipeline` parameter. If I remove it from the parameters multiple calls work as expected. Class: ``` public class MarkdigRenderer : IMarkdownRenderer { private readonly MarkdownPipeline _pipeline; public MarkdigRenderer() { _pipeline = new MarkdownPipeline().UseAllExtensions(); _pipeline.DebugLog = new StringWriter(); } public string Render(string markdown) { var html = Markdown.ToHtml(markdown, _pipeline); return html; } } ``` Exception ``` System.InvalidOperationException: The character `:` is already used by another emphasis descriptor at Markdig.Parsers.Inlines.EmphasisInlineParser.Initialize(InlineProcessor processor) at Markdig.Parsers.ParserList`2.Initialize(TState initState) at Markdig.Parsers.InlineParserList.Initialize(InlineProcessor initState) at Markdig.Parsers.InlineProcessor..ctor(StringBuilderCache stringBuilders, MarkdownDocument document, InlineParserList parsers) at Markdig.Parsers.MarkdownParser..ctor(TextReader reader, MarkdownPipeline pipeline) at Markdig.Parsers.MarkdownParser.Parse(TextReader reader, MarkdownPipeline pipeline) at Markdig.Markdown.ToHtml(TextReader reader, TextWriter writer, MarkdownPipeline pipeline) at Markdig.Markdown.ToHtml(TextReader reader, MarkdownPipeline pipeline) at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline) ```
claunia added the bug label 2026-01-29 14:19:04 +00:00
Author
Owner

@xoofx commented on GitHub (May 30, 2016):

Thanks this should be fixed by commit 09beb2f (nuget version: 0.1.1)

@xoofx commented on GitHub (May 30, 2016): Thanks this should be fixed by commit 09beb2f (nuget version: 0.1.1)
Author
Owner

@xoofx commented on GitHub (May 31, 2016):

Note that latest version (0.2.0+) is introducing a MarkdownPipelineBuilder instead to disallow mutable pipeline (related to issue #5).

Replace

var pipeline = new MarkdownPipeline().UseAllExtensions()

by:

var pipeline = new MarkdownPipelineBuilder().UseAllExtensions().Build();
@xoofx commented on GitHub (May 31, 2016): Note that latest version (0.2.0+) is introducing a `MarkdownPipelineBuilder` instead to disallow mutable pipeline (related to issue #5). Replace ``` var pipeline = new MarkdownPipeline().UseAllExtensions() ``` by: ``` var pipeline = new MarkdownPipelineBuilder().UseAllExtensions().Build(); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#6