git.iko.soy/typeable/pandoc
on master help sign in
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.

commit75f4e41d7d292e011a83d06efebc356060ea812b authorJohn MacFarlane <jgm@berkeley.edu> dateMon 26 Jun 2017, 16:07 (9 years ago) parentfa515e4
14 files changed+29−17
data/templates/default.commonmark+1−1 data/templates/default.dzslides+1−1 data/templates/default.html4+1−1 data/templates/default.html5+1−1 data/templates/default.markdown+1−1 data/templates/default.plain+1−1 data/templates/default.revealjs+1−1 data/templates/default.rtf+1−1 data/templates/default.s5+1−1 data/templates/default.slideous+1−1 data/templates/default.slidy+1−1 src/Text/Pandoc/Writers/HTML.hs+6−2 src/Text/Pandoc/Writers/Markdown.hs+7−3 src/Text/Pandoc/Writers/RTF.hs+5−1
data/templates/default.commonmark+1−1
@@ -11,7 +11,7 @@ $include-before$
1111
1212$endfor$
1313$if(toc)$
14−$toc$
14+$table-of-contents$
1515
1616$endif$
1717$body$
data/templates/default.dzslides+1−1
@@ -186,7 +186,7 @@ $endif$
186186$endif$
187187$if(toc)$
188188<section id="$idprefix$TOC">
189−$toc$
189+$table-of-contents$
190190</section>
191191$endif$
192192$for(include-before)$
data/templates/default.html4+1−1
@@ -57,7 +57,7 @@ $endif$
5757$endif$
5858$if(toc)$
5959<div id="$idprefix$TOC">
60−$toc$
60+$table-of-contents$
6161</div>
6262$endif$
6363$body$
data/templates/default.html5+1−1
@@ -60,7 +60,7 @@ $endif$
6060$endif$
6161$if(toc)$
6262<nav id="$idprefix$TOC">
63−$toc$
63+$table-of-contents$
6464</nav>
6565$endif$
6666$body$
data/templates/default.markdown+1−1
@@ -11,7 +11,7 @@ $include-before$
1111
1212$endfor$
1313$if(toc)$
14−$toc$
14+$table-of-contents$
1515
1616$endif$
1717$body$
data/templates/default.plain+1−1
@@ -11,7 +11,7 @@ $include-before$
1111
1212$endfor$
1313$if(toc)$
14−$toc$
14+$table-of-contents$
1515
1616$endif$
1717$body$
data/templates/default.revealjs+1−1
@@ -79,7 +79,7 @@ $endif$
7979$endif$
8080$if(toc)$
8181<section id="$idprefix$TOC">
82−$toc$
82+$table-of-contents$
8383</section>
8484$endif$
8585
data/templates/default.rtf+1−1
@@ -18,7 +18,7 @@ $if(spacer)$
1818{\pard \ql \f0 \sa180 \li0 \fi0 \par}
1919$endif$
2020$if(toc)$
21−$toc$
21+$table-of-contents$
2222$endif$
2323$for(include-before)$
2424$include-before$
data/templates/default.s5+1−1
@@ -78,7 +78,7 @@ $endif$
7878$endif$
7979$if(toc)$
8080<div class="slide" id="$idprefix$TOC">
81−$toc$
81+$table-of-contents$
8282</div>
8383$endif$
8484$body$
data/templates/default.slideous+1−1
@@ -83,7 +83,7 @@ $endif$
8383$endif$
8484$if(toc)$
8585<div class="slide" id="$idprefix$TOC">
86−$toc$
86+$table-of-contents$
8787</div>
8888$endif$
8989$body$
data/templates/default.slidy+1−1
@@ -69,7 +69,7 @@ $endif$
6969$endif$
7070$if(toc)$
7171<div class="slide" id="$idprefix$TOC">
72−$toc$
72+$table-of-contents$
7373</div>
7474$endif$
7575$body$
src/Text/Pandoc/Writers/HTML.hs+6−2
@@ -241,7 +241,7 @@ pandocToHtml opts (Pandoc meta blocks) = do
241241 then blocks
242242 else prepSlides slideLevel blocks
243243 toc <- if writerTableOfContents opts && slideVariant /= S5Slides
244− then tableOfContents opts sects
244+ then fmap renderHtml' <$> tableOfContents opts sects
245245 else return Nothing
246246 blocks' <- liftM (mconcat . intersperse (nl opts)) $
247247 mapM (elementToHtml slideLevel opts) sects
@@ -292,7 +292,11 @@ pandocToHtml opts (Pandoc meta blocks) = do
292292 MathJax _ -> True
293293 _ -> False) $
294294 defField "quotes" (stQuotes st) $
295− maybe id (defField "toc" . renderHtml') toc $
295+ -- for backwards compatibility we populate toc
296+ -- with the contents of the toc, rather than a
297+ -- boolean:
298+ maybe id (defField "toc") toc $
299+ maybe id (defField "table-of-contents") toc $
296300 defField "author-meta" authsMeta $
297301 maybe id (defField "date-meta") (normalizeDate dateMeta) $
298302 defField "pagetitle" (stringifyHTML (docTitle meta)) $
src/Text/Pandoc/Writers/Markdown.hs+7−3
@@ -209,8 +209,8 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
209209 Nothing -> empty
210210 let headerBlocks = filter isHeaderBlock blocks
211211 toc <- if writerTableOfContents opts
212− then tableOfContents opts headerBlocks
213− else return empty
212+ then render' <$> tableOfContents opts headerBlocks
213+ else return ""
214214 -- Strip off final 'references' header if markdown citations enabled
215215 let blocks' = if isEnabled Ext_citations opts
216216 then case reverse blocks of
@@ -220,7 +220,11 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
220220 body <- blockListToMarkdown opts blocks'
221221 notesAndRefs' <- notesAndRefs opts
222222 let main = render' $ body <> notesAndRefs'
223− let context = defField "toc" (render' toc)
223+ let context = -- for backwards compatibility we populate toc
224+ -- with the contents of the toc, rather than a
225+ -- boolean:
226+ defField "toc" toc
227+ $ defField "table-of-contents" toc
224228 $ defField "body" main
225229 $ (if isNullMeta meta
226230 then id
src/Text/Pandoc/Writers/RTF.hs+5−1
@@ -122,7 +122,11 @@ writeRTF options doc = do
122122 let context = defField "body" body
123123 $ defField "spacer" spacer
124124 $ (if writerTableOfContents options
125− then defField "toc" toc
125+ then defField "table-of-contents" toc
126+ -- for backwards compatibility,
127+ -- we populate toc with the contents
128+ -- of the toc rather than a boolean:
129+ . defField "toc" toc
126130 else id)
127131 $ metadata
128132 T.pack <$>