Skip to content

Conversation

jmooring
Copy link
Member

@jmooring jmooring commented Sep 13, 2025

This commit introduces a new option, enableAutoIDPrefix, to the Goldmark footnote extension. When enabled, it prepends a unique prefix to footnote IDs, preventing clashes when multiple documents are rendered together. This prefix is unique to each logical path, which means that the prefix is not unique across content dimensions such as language. This change also refactors the extension's configuration from a boolean to a struct.

Closes #8045

@jmooring
Copy link
Member Author

jmooring commented Sep 13, 2025

I was initially concerned that the footnote links would change if the page path changed, as the document ID is derived from it. However, I realized this is already the case whenever you insert a new footnote before an existing one—the numbering shifts, and the links change. Given that content changes are much more frequent than path changes, I believe this is an acceptable trade-off.

And how often does one link to a footnote in another document? Never, or close to it.

@jmooring jmooring marked this pull request as ready for review September 13, 2025 04:22
@bep
Copy link
Member

bep commented Sep 13, 2025

And how often does one link to a footnote in another document? Never, or close to it.

I have never seen it.

@jmooring
Copy link
Member Author

Pages created via content adapters will have the same file ID (I assume)

I have verified that this is true and will add some test cases.

@jmooring
Copy link
Member Author

creates a new ID

I have done this, and everything works fine, but having two IDs in the converter.DocumentContext struct isn't satisfying. Can we leave the f.UniqueID method as is, and simply change how DocumentID is set? For example, change this:

var id string
var filename string
var path string
if p.f != nil {
    id = p.f.UniqueID()
    filename = p.f.Filename()
    path = p.f.Path()
} else {
    path = p.Path()
}

cpp, err := cp.New(
    converter.DocumentContext{
	    Document:       doc,
	    DocumentLookup: documentLookup,
	    DocumentID:     id,
	    DocumentName:   path,
	    Filename:       filename,
    },
)

to this

var filename string
var path string
if p.f != nil {
    filename = p.f.Filename()
    path = p.f.Path()
} else {
   path = p.Path()
}

cpp, err := cp.New(
    converter.DocumentContext{
	    Document:       doc,
	    DocumentLookup: documentLookup,
	    DocumentID:     hashing.XxHashFromStringHexEncoded(p.Path()),
	    DocumentName:   path,
	    Filename:       filename,
    },
)

As you noted, DocumentID doesn't appear to be used anywhere, so it seems like changing its derivation should not be a problem.

@jmooring jmooring force-pushed the goldmark-footnote-id-prefix-8045 branch from b114129 to ea6c4d5 Compare September 22, 2025 13:19
@jmooring jmooring changed the title markup/goldmark: Add config to auto-prefix footnote IDs markup/goldmark: Enhance footnote extension with auto-prefixing option Sep 22, 2025
@jmooring
Copy link
Member Author

@bep Please see my previous comment when you have a moment.

@bep
Copy link
Member

bep commented Sep 26, 2025

to this

Yes, that was how I imagined it in tthe first place, so please do.

@jmooring jmooring force-pushed the goldmark-footnote-id-prefix-8045 branch 2 times, most recently from 3810ab9 to affacb2 Compare September 26, 2025 19:49
This commit introduces a new option, enableAutoIDPrefix, to the Goldmark
footnote extension. When enabled, it prepends a unique prefix to
footnote IDs, preventing clashes when multiple documents are rendered
together. This prefix is unique to each logical path, which means that
the prefix is not unique across content dimensions such as language.
This change also refactors the extension's configuration from a boolean
to a struct.

Closes gohugoio#8045
@jmooring jmooring force-pushed the goldmark-footnote-id-prefix-8045 branch from affacb2 to a5e2a38 Compare September 26, 2025 20:22
@bep bep merged commit 47678d8 into gohugoio:master Sep 27, 2025
5 checks passed
@jmooring jmooring deleted the goldmark-footnote-id-prefix-8045 branch September 28, 2025 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add auto-prefixing option to Goldmark's footnote extension
2 participants