Skip to content

Commit

Permalink
fix!: work around Pandoc 3.2+ breaking links to chapters (#100)
Browse files Browse the repository at this point in the history
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
jgm/pandoc@30442b7,
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](https://doc.rust-lang.org/rust-by-example/std/result/question_mark.html),
for instance). See the [Pandoc
manual](https://pandoc.org/MANUAL.html#extension-gfm_auto_identifiers)
for the algorithm used to generate identifiers for headings.

Closes #99
  • Loading branch information
max-heller authored Jun 25, 2024
1 parent 0ff1750 commit 21a287d
Show file tree
Hide file tree
Showing 11 changed files with 824 additions and 661 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ variable-name = "value"
### Known Issues
- When rendering to PDF through LaTeX, links to chapters sometimes link to slightly before the beginning of the chapter.
See: https://github.com/jgm/pandoc/issues/9200
- Linking to a chapter does not work unless the chapter contains a heading with a non-empty identifier (either auto-generated or explicitly specified).
See: https://github.com/max-heller/mdbook-pandoc/pull/100
### Comparison to alternatives
Expand Down
6 changes: 3 additions & 3 deletions scripts/install-ci-deps
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ sudo apt-get update
curl -LsSf https://get.nexte.st/0.9/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin

# Pandoc
curl -LsSf https://github.com/jgm/pandoc/releases/download/3.1.12.3/pandoc-3.1.12.3-linux-amd64.tar.gz | tar zxf -
echo "$PWD/pandoc-3.1.12.3/bin" >> $GITHUB_PATH
export PATH="$PWD/pandoc-3.1.12.3/bin:$PATH"
curl -LsSf https://github.com/jgm/pandoc/releases/download/3.2/pandoc-3.2-linux-amd64.tar.gz | tar zxf -
echo "$PWD/pandoc-3.2/bin" >> $GITHUB_PATH
export PATH="$PWD/pandoc-3.2/bin:$PATH"

# rsvg-convert (SVG support)
sudo apt-get install -y librsvg2-bin
Expand Down
Loading

0 comments on commit 21a287d

Please sign in to comment.