mirror of
https://github.com/xoofx/markdig.git
synced 2026-07-09 02:26:32 +00:00
Prefix auto-generated identifiers #473
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kirtithorat on GitHub (Jun 25, 2021).
Is it possible to add a prefix to the auto-generated identifiers? If not, then are there any plans for it to be supported in the future?
Usecase: We are using markdig in only a part of the page or multiple different parts of the same page. Planning to enable
AutoIdentifiersfor headers but we need to be able to specify our own prefix so as not to conflict with existing identifiers on a page.Will appreciate any suggestions. Thank you!
@xoofx commented on GitHub (Jul 6, 2021):
Not currently possible, no plans but PR opened and welcome 🙂
@abjerner commented on GitHub (May 11, 2023):
Being able to control the generated identifier in general would be nice. I tried having a look at extending the
AutoIdentifierExtensionclass, but most methods in the class are private. On the other hand, trying to copy the code for the class isn't easily possible either as theValueStringBuilderclass as well as theHtmlRenderer.Resetmethod are both internal.Would a PR to change the
AutoIdentifierExtensionmethods fromprivatetoprotected virtualbe accepted?Right now the urilization of each identifier is handled by either of the
LinkHelper.UrilizeorLinkHelper.UrilizeAsGfmmethods depending of the options. Would moving this a new protected virtualUrilizemethod be accepted as well? I'm not thinking moving the urilization logic to this method - instead the default implementation would call either of these methods as today. But the new method being virtual would allow developers to override it.@MihaZupan commented on GitHub (May 11, 2023):
FWIW modifying the generated ID after parsing may be simpler:
@abjerner commented on GitHub (May 11, 2023):
Thanks. My use case was to handle certain special characters before they are stripped for the ID. But this could possibly work as well 👍
@MihaZupan commented on GitHub (May 11, 2023):
Note that you have access to the original information as well via the
HeadingBlock, so you can create a new id from scratch this way too@abjerner commented on GitHub (May 11, 2023):
Yes, I assumed from your snippet that something like that would be possible as well. After playing a bit around with the code, I ended up like the method below. I'm not super familiar with the inner workings of Markdig, so maybe it can be done more efficient - but this as least does the job.
For one, my issue was that
C#was converted toc. With the method below, it's now converted tocsharpinstead 😎Thanks for the pointers 👍