markdig icon indicating copy to clipboard operation
markdig copied to clipboard

Unable to set AutoIdentifierOptions to None / disable

Open olafdemol opened this issue 8 years ago • 7 comments

var pipeline = new MarkdownPipelineBuilder() .UseAutoIdentifiers(Markdig.Extensions.AutoIdentifiers.AutoIdentifierOptions.None) .Build();

Does not seem to do anything compared to Default or any of the other options. Maybe something is broken? My use case is that I want to use all of the AdvancedExtensions but disable the auto-identifier option.

olafdemol avatar Nov 07 '18 15:11 olafdemol

new MarkdownPipelineBuilder(); will build only a CommonMark pipeline without any advanced extensions.

If you want to remove one extension, you could just create a builder with advanced, and remove the extension manually, something like this:

var builder = new MarkdownPipelineBuilder().UseAdvancedExtensions();
builder.Extensions.Remove(pipeline.Extensions.Find<AutoIdentifierExtension>());
var pipeline = builder.Build();

There is a missing method pipeline.Extensions.Remove<AutoIdentifierExtension>(); but otherwise, you should be able to do what you are looking for.

xoofx avatar Nov 07 '18 15:11 xoofx

Thanks for the quick reply!

One thing I'm wondering about is what Markdig.Extensions.AutoIdentifiers.AutoIdentifierOptions.None actually does. In my case it did not seem to be any different from Markdig.Extensions.AutoIdentifiers.AutoIdentifierOptions.Default. I assumed none would mean the option was disabled, however it acts the same as default. Is this a bug? (I was not using .UseAdvancedExtensions() in this case).

olafdemol avatar Nov 08 '18 07:11 olafdemol

I guess it is just here because the enum is a flag and it is recommended to always define (name) the 0 value. That said I would have named it Undefined to make sure nobody uses it.

Alternatively the UseAutoIdentifiers extension method could just check the option and if it is None do not add (or even remove in case it was already added).

Kryptos-FR avatar Nov 08 '18 08:11 Kryptos-FR

I guess it is just here because the enum is a flag and it is recommended to always define (name) the 0 value. That said I would have named it Undefined to make sure nobody uses it.

Alternatively the UseAutoIdentifiers extension method could just check the option and if it is None do not add (or even remove in case it was already added).

Exactly, if I have time this weekend I'll write up a PR.

olafdemol avatar Nov 08 '18 09:11 olafdemol

Not sure I want to change the name (it would be a breaking change). We should maybe better just throw an exception if None is passed.

xoofx avatar Nov 08 '18 09:11 xoofx

...but that too would be a breaking change, a worse one because it's at runtime instead of compile time. Probably best to update the documentation or rename it. It's an easy compile time edit.

stevehurcombe avatar Nov 08 '18 09:11 stevehurcombe

yes, that's true 😉... so let's keep it as it is today with a proper comment on the None enum.

xoofx avatar Nov 08 '18 09:11 xoofx