From ae987b236bd7b76fefd16bfd97ab9a2a80fba91e Mon Sep 17 00:00:00 2001 From: Everett Hildenbrandt Date: Thu, 10 May 2018 21:33:49 -0600 Subject: [PATCH] tools/pandoc-site: pass in generated toc from top-level filter --- tools/pandoc-site.hs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tools/pandoc-site.hs b/tools/pandoc-site.hs index 11daabdcc..7ceaf1aae 100644 --- a/tools/pandoc-site.hs +++ b/tools/pandoc-site.hs @@ -64,18 +64,17 @@ createTable alignment headers tocString = unpack . fromRight mempty . runPure . writeHtml5String def $ tocDoc in RawBlock "html" (navBegin ++ "\n" ++ tocString ++ "\n" ++ navEnd) -generateTOC :: [Block] -> TOCAlignment -> Block -> Block -generateTOC headers alignment x@(BulletList (( (( Plain ((Str "toc"):_)):_)):_)) - = createTable alignment . groupByHierarchy $ headers -generateTOC _ _ x = x +generateTOC :: Block -> Block -> Block +generateTOC toc (BulletList (( (( Plain ((Str "toc"):_)):_)):_)) + = toc +generateTOC _ x = x tableOfContents :: TOCAlignment -> Pandoc -> Pandoc +tableOfContents TOCOff ast = walk ignoreTOC ast tableOfContents alignment ast - = let headers = query collectHeaders ast - tocGen = case alignment of - TOCOff -> walk ignoreTOC - _ -> walk (generateTOC headers alignment) - in tocGen $ ast + = let headers = query collectHeaders ast + toc = createTable alignment . groupByHierarchy $ headers + in walk (generateTOC toc) ast main :: IO () main = toJSONFilter (tableOfContents TOCRight)