Jaguir
Jaguir

Reputation: 3680

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?

Upvotes: 4

Views: 2108

Answers (3)

Martijn Courteaux
Martijn Courteaux

Reputation: 68847

I had this problem when using the markdown_phpextra reader. Using the markdown reader works fine. I used the markdown_phpextra because I read somewhere that the link-attributes extension was only supported in this one, but it's not true. Works fine in the default markdown reader.

Upvotes: 0

Jaguir
Jaguir

Reputation: 3680

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.

Upvotes: 1

John MacFarlane
John MacFarlane

Reputation: 8937

This may be a bug in pandoc; you should report on pandoc's github issue tracker.

For your purposes, though, you're better off using the --toc command line flag, instead of manually creating a table of contents for each chapter. This will cause each chapter to begin with a table of contents, which you can style using CSS.

Upvotes: 3

Related Questions