Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 786
Jaguir Avatar asked Oct 27 '25 23:10

Jaguir


1 Answers

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.

like image 65
John MacFarlane Avatar answered Oct 30 '25 20:10

John MacFarlane



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!