fix: generate IDs for HTML headings without id attribute (#36233)
This PR fixes #27383 where HTML headings like `<h1>Title</h1>` in markdown files would have empty permalink anchors --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
committed by
GitHub
parent
1d01286f4c
commit
f9d3983de2
@@ -54,6 +54,10 @@ type RenderOptions struct {
|
||||
|
||||
// used by external render. the router "/org/repo/render/..." will output the rendered content in a standalone page
|
||||
InStandalonePage bool
|
||||
|
||||
// EnableHeadingIDGeneration controls whether to auto-generate IDs for HTML headings without id attribute.
|
||||
// This should be enabled for repository files and wiki pages, but disabled for comments to avoid duplicate IDs.
|
||||
EnableHeadingIDGeneration bool
|
||||
}
|
||||
|
||||
// RenderContext represents a render context
|
||||
@@ -112,6 +116,11 @@ func (ctx *RenderContext) WithInStandalonePage(v bool) *RenderContext {
|
||||
return ctx
|
||||
}
|
||||
|
||||
func (ctx *RenderContext) WithEnableHeadingIDGeneration(v bool) *RenderContext {
|
||||
ctx.RenderOptions.EnableHeadingIDGeneration = v
|
||||
return ctx
|
||||
}
|
||||
|
||||
func (ctx *RenderContext) WithUseAbsoluteLink(v bool) *RenderContext {
|
||||
ctx.RenderOptions.UseAbsoluteLink = v
|
||||
return ctx
|
||||
|
||||
Reference in New Issue
Block a user