diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2023-01-18 11:15:57 -0800 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2023-01-18 11:15:57 -0800 |
| commit | 8a1f4ad513cfbf922d8695e52daefe82f9f9fe80 (patch) | |
| tree | 579951309f860a5084c74ace73b843566a415277 | |
| parent | 27d2dc682174f9359110be2c8ac4a772c49cd0b1 (diff) | |
Add param to tocToList for numberSections.
Otherwise sections are always numbered in the TOC,
even if `--number-sections` is not used.
| -rw-r--r-- | pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Structure.hs | 6 | ||||
| -rw-r--r-- | src/Text/Pandoc/Chunks.hs | 15 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/ChunkedHTML.hs | 2 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/Shared.hs | 2 |
4 files changed, 14 insertions, 11 deletions
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Structure.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Structure.hs index 56977edae..21248c724 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Structure.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Structure.hs @@ -29,7 +29,8 @@ import Text.Pandoc.Lua.Marshal.AST ( peekBlocksFuzzy, peekPandoc , pushBlock, pushBlocks ) import Text.Pandoc.Lua.Marshal.Chunks import Text.Pandoc.Lua.Marshal.WriterOptions ( peekWriterOptions ) -import Text.Pandoc.Options (WriterOptions (writerTOCDepth)) +import Text.Pandoc.Options (WriterOptions (writerTOCDepth, + writerNumberSections)) import Text.Pandoc.Slides (getSlideLevel, prepSlides) import Text.Pandoc.Writers.Shared (toTableOfContents) import qualified Data.Text as T @@ -168,7 +169,8 @@ table_of_contents = defun "table_of_contents" let writerOpts = fromMaybe def mwriterOpts in case tocSource of Left blks -> toTableOfContents writerOpts blks - Right tree -> tocToList (writerTOCDepth writerOpts) tree + Right tree -> tocToList (writerNumberSections writerOpts) + (writerTOCDepth writerOpts) tree ) <#> parameter peekTocSource "Blocks|Pandoc|ChunkedDoc" "toc_source" "list of command line arguments" diff --git a/src/Text/Pandoc/Chunks.hs b/src/Text/Pandoc/Chunks.hs index 196893f04..9ba282999 100644 --- a/src/Text/Pandoc/Chunks.hs +++ b/src/Text/Pandoc/Chunks.hs @@ -374,13 +374,14 @@ fixTOCTreePaths chunks = go "" (map (go fp') subtrees) -- | Creates a TOC link to the respective document section. -tocEntryToLink :: SecInfo -> [Inline] -tocEntryToLink secinfo = headerLink +tocEntryToLink :: Bool -> SecInfo -> [Inline] +tocEntryToLink includeNumbers secinfo = headerLink where addNumber = case secNumber secinfo of - Just num -> (Span ("",["toc-section-number"],[]) + Just num | includeNumbers + -> (Span ("",["toc-section-number"],[]) [Str num] :) . (Space :) - Nothing -> id + _ -> id clean (Link _ xs _) = xs clean (Note _) = [] clean x = [x] @@ -398,13 +399,13 @@ tocEntryToLink secinfo = headerLink headerText (anchor, "")] -- | Generate a table of contents of the given depth. -tocToList :: Int -> Tree SecInfo -> Block -tocToList tocDepth (Node _ subtrees) = BulletList (toItems subtrees) +tocToList :: Bool -> Int -> Tree SecInfo -> Block +tocToList includeNumbers tocDepth (Node _ subtrees) = BulletList (toItems subtrees) where toItems = map go . filter isBelowTocDepth isBelowTocDepth (Node sec _) = secLevel sec <= tocDepth go (Node secinfo xs) = - Plain (tocEntryToLink secinfo) : + Plain (tocEntryToLink includeNumbers secinfo) : case toItems xs of [] -> [] ys -> [BulletList ys] diff --git a/src/Text/Pandoc/Writers/ChunkedHTML.hs b/src/Text/Pandoc/Writers/ChunkedHTML.hs index 9757cbe6e..cc84ce3d6 100644 --- a/src/Text/Pandoc/Writers/ChunkedHTML.hs +++ b/src/Text/Pandoc/Writers/ChunkedHTML.hs @@ -110,7 +110,7 @@ addMedia il@(Image _ _ (src,_)) addMedia il = return il buildTOC :: WriterOptions -> Tree SecInfo -> Block -buildTOC opts = tocToList (writerTOCDepth opts) +buildTOC opts = tocToList (writerNumberSections opts) (writerTOCDepth opts) chunkToEntry :: PandocMonad m => WriterOptions -> Meta -> Chunk -> Chunk -> m Entry diff --git a/src/Text/Pandoc/Writers/Shared.hs b/src/Text/Pandoc/Writers/Shared.hs index 723f55b8a..3d64f83f0 100644 --- a/src/Text/Pandoc/Writers/Shared.hs +++ b/src/Text/Pandoc/Writers/Shared.hs @@ -465,7 +465,7 @@ toTableOfContents :: WriterOptions -> [Block] -> Block toTableOfContents opts = - tocToList (writerTOCDepth opts) + tocToList (writerNumberSections opts) (writerTOCDepth opts) . toTOCTree . makeSections (writerNumberSections opts) Nothing |
