Can the interpetation of code blocks formed from indented lines be turned off? #305

Closed
opened 2026-01-29 14:33:16 +00:00 by claunia · 3 comments
Owner

Originally created by @deanebarker on GitHub (Jun 19, 2019).

For a variety of pre-processing reasons, some of my lines of markdown end up with leading spaces. MarkDig interprets this as a code block, which I really don't want. I'd like it to be ignored.

Is there any way to shut off this specific rule? I don't really have any code blocks in this particular body of content, and if I did, I could fence it with other blocks.

Originally created by @deanebarker on GitHub (Jun 19, 2019). For a variety of pre-processing reasons, some of my lines of markdown end up with leading spaces. MarkDig interprets this as a code block, which I really don't want. I'd like it to be ignored. Is there any way to shut off this specific rule? I don't really have any code blocks in this particular body of content, and if I did, I could fence it with other blocks.
Author
Owner

@MihaZupan commented on GitHub (Jun 19, 2019):

Indented code blocks are handeled by the IndentedCodeBlockParser. Simply remove it from the pipeline.

var builder = new MarkdownPipelineBuilder()
    .UseAdvancedExtensions();

builder.BlockParsers.TryRemove<IndentedCodeBlockParser>();

var pipeline = builder.Build();

string html = Markdown.ToHtml(markdown, pipeline);
@MihaZupan commented on GitHub (Jun 19, 2019): Indented code blocks are handeled by the `IndentedCodeBlockParser`. Simply remove it from the pipeline. ```c# var builder = new MarkdownPipelineBuilder() .UseAdvancedExtensions(); builder.BlockParsers.TryRemove<IndentedCodeBlockParser>(); var pipeline = builder.Build(); string html = Markdown.ToHtml(markdown, pipeline); ```
Author
Owner

@deanebarker commented on GitHub (Jun 20, 2019):

Wonderful, thank you.

For some reason, my version of Markdig didn't have TryRemove. I did this instead.

var indentedCodeBlock = builder.BlockParsers.FirstOrDefault(p => p.GetType() == typeof(IndentedCodeBlockParser));
builder.BlockParsers.Remove(indentedCodeBlock);
@deanebarker commented on GitHub (Jun 20, 2019): Wonderful, thank you. For some reason, my version of Markdig didn't have `TryRemove`. I did this instead. ``` var indentedCodeBlock = builder.BlockParsers.FirstOrDefault(p => p.GetType() == typeof(IndentedCodeBlockParser)); builder.BlockParsers.Remove(indentedCodeBlock); ```
Author
Owner

@ferventcoder commented on GitHub (Jan 2, 2020):

Thanks! I was just in looking for this. Might not be a bad idea to add this to the MarkdigExtensions to disable these.

@ferventcoder commented on GitHub (Jan 2, 2020): Thanks! I was just in looking for this. Might not be a bad idea to add this to the MarkdigExtensions to disable these.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#305