Add autoID for definition terms

Fixes #13403
See #11566

Co-authored-by: Joe Mooring <joe@mooring.com>
This commit is contained in:
Bjørn Erik Pedersen
2025-02-15 17:13:20 +01:00
parent 9c2f8ec61b
commit 157d3703c3
9 changed files with 262 additions and 47 deletions

View File

@@ -15,9 +15,9 @@
package goldmark_config
const (
AutoHeadingIDTypeGitHub = "github"
AutoHeadingIDTypeGitHubAscii = "github-ascii"
AutoHeadingIDTypeBlackfriday = "blackfriday"
AutoIDTypeGitHub = "github"
AutoIDTypeGitHubAscii = "github-ascii"
AutoIDTypeBlackfriday = "blackfriday"
)
// Default holds the default Goldmark configuration.
@@ -79,7 +79,8 @@ var Default = Config{
},
Parser: Parser{
AutoHeadingID: true,
AutoHeadingIDType: AutoHeadingIDTypeGitHub,
AutoDefinitionTermID: false,
AutoIDType: AutoIDTypeGitHub,
WrapStandAloneImageWithinParagraph: true,
Attribute: ParserAttribute{
Title: true,
@@ -97,6 +98,16 @@ type Config struct {
RenderHooks RenderHooks
}
func (c *Config) Init() error {
if err := c.Parser.Init(); err != nil {
return err
}
if c.Parser.AutoDefinitionTermID && !c.Extensions.DefinitionList {
c.Parser.AutoDefinitionTermID = false
}
return nil
}
// RenderHooks contains configuration for Goldmark render hooks.
type RenderHooks struct {
Image ImageRenderHook
@@ -250,16 +261,30 @@ type Parser struct {
// auto generated heading ids.
AutoHeadingID bool
// The strategy to use when generating heading IDs.
// Available options are "github", "github-ascii".
// Enables auto definition term ids.
AutoDefinitionTermID bool
// The strategy to use when generating IDs.
// Available options are "github", "github-ascii", and "blackfriday".
// Default is "github", which will create GitHub-compatible anchor names.
AutoHeadingIDType string
AutoIDType string
// Enables custom attributes.
Attribute ParserAttribute
// Whether to wrap stand-alone images within a paragraph or not.
WrapStandAloneImageWithinParagraph bool
// Renamed to AutoIDType in 0.144.0.
AutoHeadingIDType string `json:"-"`
}
func (p *Parser) Init() error {
// Renamed from AutoHeadingIDType to AutoIDType in 0.144.0.
if p.AutoHeadingIDType != "" {
p.AutoIDType = p.AutoHeadingIDType
}
return nil
}
type ParserAttribute struct {