max-heller / mdbook-pandoc

A mdbook backend powered by Pandoc.
Apache License 2.0
97 stars 7 forks source link

fix!: work around Pandoc 3.2+ breaking links to chapters #100

Closed max-heller closed 2 months ago

max-heller commented 2 months ago

Pandoc used to wrap the contents of each file in a div when --file-scope was used, which mdbook-pandoc relied on to link to the start of a chapter. This behavior was removed in https://github.com/jgm/pandoc/commit/30442b7f9d27150c249a8381fe8a5ca5a460db63, which was released in version 3.2.

To work around this, mdbook-pandoc now searches for the first heading in each chapter and, if present, links to this heading as a proxy for the beginning of the chapter. This should make sense in most cases, since mdBook chapters tend to start with a top-level heading, but will result in regressions if chapters don't contain any headings or the headings they do contain don't have a usable identifier (this is the case with punctuation-only headings, for instance). See the Pandoc manual for the algorithm used to generate identifiers for headings.

Closes #99