Sasgorilla
Sasgorilla

Reputation: 3130

How can I create an Asciidoc table of contents from external files?

The Asciidoc :toc: command creates a nicely formatted table of contents from the headings in the document:

:toc:

= Part 1

= Part 2

= Part 3

enter image description here

But I want my table of contents to link to other documents, instead of pulling from the document itself:

link:part1.adoc[Part 1]

link:part2.adoc[Part 2]

link:part3.adoc[Part 3]

Is there a way to create a TOC from links to other files? If not, what styles/blocks/whatever can I use to mimic the style of the TOC as closely as possible?

Upvotes: 4

Views: 3699

Answers (1)

eskwayrd
eskwayrd

Reputation: 4521

Yes, however, it may not behave the way you intend.

= Document
:toc:

== link:part1.adoc[Part 1]

== link:part2.adoc[Part 2]

== link:part3.adoc[Part 3]

That produces a table of contents, but its links point to the headings in the same file: that's what the :toc: is for. The headings themselves are links to the other documents.

You can create your own list, but to approximate the styling of the on-page TOC, you need to create a docinfo.html file containing the CSS you'd like to use:

<style>
.mytoc ul {
  list-style-type: none;
  margin-left: 0;
  font-family: sans-serif;
}

.mytoc li {
  margin: 0;
  padding: 0;
}
</style>

and specify that you want to use the docinfo file:

= Document
:docinfo: shared

[.mytoc]
== Table of Contents

* link:part1.adoc[Part 1]

* link:part2.adoc[Part 2]

* link:part3.adoc[Part 3]

Note that the styles I included aren't a comprehensive recreation of the the on-page TOC's styles, but hopefully they are enough to show you the way.

See https://asciidoctor.org/docs/user-manual/#docinfo-file for more information on docinfo files.

Upvotes: 2

Related Questions