jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.37k stars 3.37k forks source link

Custom Title Table of Contents for epub3 adds chapter link to every page along with custom title generated toc is untouched #4829

Closed naeluh closed 6 years ago

naeluh commented 6 years ago

Version: pandoc 2.2.3.2 Compiled with pandoc-types 1.17.5.1, texmath 0.11.0.1, skylighting 0.7.2 Copyright (C) 2006-2018 John MacFarlane

I was trying to alter the table of contents by downloading the template by using

pandoc -D epub3

Then I added

    $if(toc)$
    $if(toc-title)$
    $toc-title$
    $endif$
    $toc$
    $endif$

to the template

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" $if(lang)$ xml:lang="$lang$" $endif$>

<head>
    <meta charset="utf-8" />
    <meta name="generator" content="pandoc" />
    <title>$pagetitle$</title>
    <style type="text/css">
        code {
            white-space: pre-wrap;
        }

        span.smallcaps {
            font-variant: small-caps;
        }

        span.underline {
            text-decoration: underline;
        }

        div.column {
            display: inline-block;
            vertical-align: top;
            width: 50%;
        }

        html body {
            margin: 0;
        }

        body {
            margin: 5%;
            text-align: justify;
            font-size: medium;
            font-family: Georgia, Times, "Times New Roman", serif;
        }

        code {
            font-family: monospace;
        }

        h1,
        h2,
        h3,
        h4,
        h5,
        h6 {
            text-align: left;
        }

        ol.toc {
            padding: 0;
            margin-left: 1em;
        }

        ol.toc li {
            list-style-type: none;
            margin: 0;
            padding: 0;
        }

        a.footnote-ref {
            vertical-align: super;
        }

        p {
            padding: 0;
            margin: 0;
            text-indent: 1em;
        }

        blockquote {
            margin-left: 3em;
            margin-right: 3em;
        }

        blockquote>p {
            text-indent: 0;
            margin-bottom: 1em;
        }

        $if(quotes)$ q {
            quotes: "“" "”" "‘" "’";
        }

        $endif$
    </style>
    $if(highlighting-css)$
    <style type="text/css">
        $highlighting-css$
    </style>
    $endif$ $for(css)$
    <link rel="stylesheet" type="text/css" href="$css$" /> $endfor$ $for(header-includes)$ $header-includes$ $endfor$
</head>
<body$if(coverpage)$ id="cover" $else$ id="$pagetitle$" $endif$>

    $if(titlepage)$
    <section epub:type="titlepage">
        $for(title)$ $if(title.type)$
        <h1 class="$title.type$">$title.text$</h1>
        $else$
        <h1 class="title">$title$</h1>
        $endif$ $endfor$ $if(subtitle)$
        <p class="subtitle">$subtitle$</p>
        $endif$ $for(author)$
        <p class="author">$author$</p>
        $endfor$ $for(creator)$
        <p class="$creator.role$">$creator.text$</p>
        $endfor$ $if(publisher)$
        <p class="publisher">$publisher$</p>
        $endif$ $if(date)$
        <p class="date">$date$</p>
        $endif$ $if(rights)$
        <div class="rights">$rights$</div>
        $endif$
    </section>
    $else$ 

    $for(include-before)$ 
    $include-before$ 
    $endfor$ 

    $body$ 

    $if(toc)$
    $if(toc-title)$
    $toc-title$
    $endif$
    $toc$
    $endif$

    $for(include-after)$ 
    $include-after$ 
    $endfor$ 

    $endif$
    </body>

</html>

then to access the template and new variable I added the appropriate flags

--toc --toc-depth=2 --template=template.xhtml -V toc-title:'Table of Contents'

Here is the full command:

pandoc -f html-native_divs-native_spans -t epub title.xhtml cover.xhtml french-art.xhtml catalogue.xhtml catalogue__1.xhtml catalogue__2.xhtml catalogue__3.xhtml contributors.xhtml about.xhtml title.xhtml -o ebook.epub --epub-metadata=metadata.yml --epub-cover-image=../static/img/promo_image.png --template=template.xhtml --toc --toc-depth=2 -V toc-title:'Table of Contents'

The expected behavior was:

That $if(toc)$ would become true one time on the Table of Contents page and alter the output of the generated Table of Contents

The actual behavior was:

Table of Contents and a link to the chapter was printed atop every chapter page generated.

jgm commented 6 years ago

Try putting this inside a conditional

$if(navpage)$
...
$endif$

That variable is set for nav.xhtml but not the other pages.

naeluh commented 6 years ago

@jgm thanks this worked

Is there a way to expose more of these variables from the template?

jgm commented 6 years ago

By 'expose' do you mean 'document' or something else? Many of the template variables are documented, but navpage is designed to be set internally by pandoc, which is probably why it wasn't.