Search code examples
markdownepubpandoc

My TOC links in a pandoc generated epub are not working


A title of "# Project Info" creates an element with the id "project-info". I can then link to that with "#project-info". When I have only one file, this works as expected. Here is what is happening: I have many files, project-a.md, project-b.md, etc.

All of these files have this same structure:

# Title

TOC: [Info](#project-info) | [Build](#project-build) | ...

## Project Info

## Project Build

...

I am creating an epub like this:

pandoc -S -o projects.epub title.txt project-a.md project-b.md project-c.md

The problem is that in the generated epub, the toc links for every project point to the sections for project a, instead of the respective project page. I opened the epub and the links are being rendered as this:

<a href="ch5.xhtml#project-info">Info</a>

This explains why they are linking to the first project but why is it adding ch5.xhtml to the link? Is there a to prevent this?


Solution

  • Pandoc is concatenating the input files into one document first. This creates duplicate #names because they are now all in one file. This explains why the links are all jumping to the first project's bookmarks.

    The solution is to make the #names unique across all input documents or use --TOC as John suggests.