Use table-of-contents for contents of toc, make toc a boolean.

Changed markdown, rtf, and HTML-based templates accordingly.

This allows you to set `toc: true` in the metadata; this
previously produced strange results in some output formats.

Closes #2872.

For backwards compatibility, `toc` is still set to the
toc contents.  But it is recommended that you update templates
to use `table-of-contents` for the toc contents and `toc`
for a boolean flag.
This commit is contained in:
John MacFarlane 2017-06-26 16:07:59 +02:00
parent fa515e46f3
commit 75f4e41d7d
14 changed files with 29 additions and 17 deletions

View file

@ -11,7 +11,7 @@ $include-before$
$endfor$ $endfor$
$if(toc)$ $if(toc)$
$toc$ $table-of-contents$
$endif$ $endif$
$body$ $body$

View file

@ -186,7 +186,7 @@ $endif$
$endif$ $endif$
$if(toc)$ $if(toc)$
<section id="$idprefix$TOC"> <section id="$idprefix$TOC">
$toc$ $table-of-contents$
</section> </section>
$endif$ $endif$
$for(include-before)$ $for(include-before)$

View file

@ -57,7 +57,7 @@ $endif$
$endif$ $endif$
$if(toc)$ $if(toc)$
<div id="$idprefix$TOC"> <div id="$idprefix$TOC">
$toc$ $table-of-contents$
</div> </div>
$endif$ $endif$
$body$ $body$

View file

@ -60,7 +60,7 @@ $endif$
$endif$ $endif$
$if(toc)$ $if(toc)$
<nav id="$idprefix$TOC"> <nav id="$idprefix$TOC">
$toc$ $table-of-contents$
</nav> </nav>
$endif$ $endif$
$body$ $body$

View file

@ -11,7 +11,7 @@ $include-before$
$endfor$ $endfor$
$if(toc)$ $if(toc)$
$toc$ $table-of-contents$
$endif$ $endif$
$body$ $body$

View file

@ -11,7 +11,7 @@ $include-before$
$endfor$ $endfor$
$if(toc)$ $if(toc)$
$toc$ $table-of-contents$
$endif$ $endif$
$body$ $body$

View file

@ -79,7 +79,7 @@ $endif$
$endif$ $endif$
$if(toc)$ $if(toc)$
<section id="$idprefix$TOC"> <section id="$idprefix$TOC">
$toc$ $table-of-contents$
</section> </section>
$endif$ $endif$

View file

@ -18,7 +18,7 @@ $if(spacer)$
{\pard \ql \f0 \sa180 \li0 \fi0 \par} {\pard \ql \f0 \sa180 \li0 \fi0 \par}
$endif$ $endif$
$if(toc)$ $if(toc)$
$toc$ $table-of-contents$
$endif$ $endif$
$for(include-before)$ $for(include-before)$
$include-before$ $include-before$

View file

@ -78,7 +78,7 @@ $endif$
$endif$ $endif$
$if(toc)$ $if(toc)$
<div class="slide" id="$idprefix$TOC"> <div class="slide" id="$idprefix$TOC">
$toc$ $table-of-contents$
</div> </div>
$endif$ $endif$
$body$ $body$

View file

@ -83,7 +83,7 @@ $endif$
$endif$ $endif$
$if(toc)$ $if(toc)$
<div class="slide" id="$idprefix$TOC"> <div class="slide" id="$idprefix$TOC">
$toc$ $table-of-contents$
</div> </div>
$endif$ $endif$
$body$ $body$

View file

@ -69,7 +69,7 @@ $endif$
$endif$ $endif$
$if(toc)$ $if(toc)$
<div class="slide" id="$idprefix$TOC"> <div class="slide" id="$idprefix$TOC">
$toc$ $table-of-contents$
</div> </div>
$endif$ $endif$
$body$ $body$

View file

@ -241,7 +241,7 @@ pandocToHtml opts (Pandoc meta blocks) = do
then blocks then blocks
else prepSlides slideLevel blocks else prepSlides slideLevel blocks
toc <- if writerTableOfContents opts && slideVariant /= S5Slides toc <- if writerTableOfContents opts && slideVariant /= S5Slides
then tableOfContents opts sects then fmap renderHtml' <$> tableOfContents opts sects
else return Nothing else return Nothing
blocks' <- liftM (mconcat . intersperse (nl opts)) $ blocks' <- liftM (mconcat . intersperse (nl opts)) $
mapM (elementToHtml slideLevel opts) sects mapM (elementToHtml slideLevel opts) sects
@ -292,7 +292,11 @@ pandocToHtml opts (Pandoc meta blocks) = do
MathJax _ -> True MathJax _ -> True
_ -> False) $ _ -> False) $
defField "quotes" (stQuotes st) $ defField "quotes" (stQuotes st) $
maybe id (defField "toc" . renderHtml') toc $ -- for backwards compatibility we populate toc
-- with the contents of the toc, rather than a
-- boolean:
maybe id (defField "toc") toc $
maybe id (defField "table-of-contents") toc $
defField "author-meta" authsMeta $ defField "author-meta" authsMeta $
maybe id (defField "date-meta") (normalizeDate dateMeta) $ maybe id (defField "date-meta") (normalizeDate dateMeta) $
defField "pagetitle" (stringifyHTML (docTitle meta)) $ defField "pagetitle" (stringifyHTML (docTitle meta)) $

View file

@ -209,8 +209,8 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
Nothing -> empty Nothing -> empty
let headerBlocks = filter isHeaderBlock blocks let headerBlocks = filter isHeaderBlock blocks
toc <- if writerTableOfContents opts toc <- if writerTableOfContents opts
then tableOfContents opts headerBlocks then render' <$> tableOfContents opts headerBlocks
else return empty else return ""
-- Strip off final 'references' header if markdown citations enabled -- Strip off final 'references' header if markdown citations enabled
let blocks' = if isEnabled Ext_citations opts let blocks' = if isEnabled Ext_citations opts
then case reverse blocks of then case reverse blocks of
@ -220,7 +220,11 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
body <- blockListToMarkdown opts blocks' body <- blockListToMarkdown opts blocks'
notesAndRefs' <- notesAndRefs opts notesAndRefs' <- notesAndRefs opts
let main = render' $ body <> notesAndRefs' let main = render' $ body <> notesAndRefs'
let context = defField "toc" (render' toc) let context = -- for backwards compatibility we populate toc
-- with the contents of the toc, rather than a
-- boolean:
defField "toc" toc
$ defField "table-of-contents" toc
$ defField "body" main $ defField "body" main
$ (if isNullMeta meta $ (if isNullMeta meta
then id then id

View file

@ -122,7 +122,11 @@ writeRTF options doc = do
let context = defField "body" body let context = defField "body" body
$ defField "spacer" spacer $ defField "spacer" spacer
$ (if writerTableOfContents options $ (if writerTableOfContents options
then defField "toc" toc then defField "table-of-contents" toc
-- for backwards compatibility,
-- we populate toc with the contents
-- of the toc rather than a boolean:
. defField "toc" toc
else id) else id)
$ metadata $ metadata
T.pack <$> T.pack <$>