git.iko.soy/typeable/pandoc
on master help sign in
Make some writers sensitive to 'unlisted' class on headings.
68b09a6John MacFarlane
MANUAL.txt+5
@@ -2712,6 +2712,11 @@ is just the same as
2712
2712
2713 # My heading {.unnumbered}
2713 # My heading {.unnumbered}
2714
2714
2715+If the `unlisted` class is present in addition to `unnumbered`,
2716+the heading will not be included in a table of contents.
2717+(Currently this feature is only implemented for certain
2718+formats: those based on LaTeX and HTML, PowerPoint, and RTF.)
2719+
2715#### Extension: `implicit_header_references` ####
2720#### Extension: `implicit_header_references` ####
2716
2721
2717Pandoc behaves as if reference links have been defined for each heading.
2722Pandoc behaves as if reference links have been defined for each heading.
src/Text/Pandoc/Writers/LaTeX.hs+6−4
@@ -748,7 +748,7 @@ blockToLaTeX HorizontalRule =
748 "\\begin{center}\\rule{0.5\\linewidth}{\\linethickness}\\end{center}"
748 "\\begin{center}\\rule{0.5\\linewidth}{\\linethickness}\\end{center}"
749blockToLaTeX (Header level (id',classes,_) lst) = do
749blockToLaTeX (Header level (id',classes,_) lst) = do
750 modify $ \s -> s{stInHeading = True}
750 modify $ \s -> s{stInHeading = True}
751− hdr <- sectionHeader ("unnumbered" `elem` classes) id' level lst
751+ hdr <- sectionHeader classes id' level lst
752 modify $ \s -> s{stInHeading = False}
752 modify $ \s -> s{stInHeading = False}
753 return hdr
753 return hdr
754blockToLaTeX (Table caption aligns widths heads rows) = do
754blockToLaTeX (Table caption aligns widths heads rows) = do
@@ -949,12 +949,14 @@ defListItemToLaTeX (term, defs) = do
949
949
950-- | Craft the section header, inserting the secton reference, if supplied.
950-- | Craft the section header, inserting the secton reference, if supplied.
951sectionHeader :: PandocMonad m
951sectionHeader :: PandocMonad m
952− => Bool -- True for unnumbered
952+ => [String] -- classes
953 -> [Char]
953 -> [Char]
954 -> Int
954 -> Int
955 -> [Inline]
955 -> [Inline]
956 -> LW m (Doc Text)
956 -> LW m (Doc Text)
957−sectionHeader unnumbered ident level lst = do
957+sectionHeader classes ident level lst = do
958+ let unnumbered = "unnumbered" `elem` classes
959+ let unlisted = "unlisted" `elem` classes
958 txt <- inlineListToLaTeX lst
960 txt <- inlineListToLaTeX lst
959 plain <- stringToLaTeX TextString $ concatMap stringify lst
961 plain <- stringToLaTeX TextString $ concatMap stringify lst
960 let removeInvalidInline (Note _) = []
962 let removeInvalidInline (Note _) = []
@@ -1013,7 +1015,7 @@ sectionHeader unnumbered ident level lst = do
1013 return $ if level' > 5
1015 return $ if level' > 5
1014 then txt
1016 then txt
1015 else prefix $$ stuffing'
1017 else prefix $$ stuffing'
1016− $$ if unnumbered
1018+ $$ if unnumbered && not unlisted
1017 then "\\addcontentsline{toc}" <>
1019 then "\\addcontentsline{toc}" <>
1018 braces (text sectionType) <>
1020 braces (text sectionType) <>
1019 braces txtNoNotes
1021 braces txtNoNotes
src/Text/Pandoc/Writers/Shared.hs+4−3
@@ -40,7 +40,7 @@ where
40import Prelude
40import Prelude
41import Safe (lastMay)
41import Safe (lastMay)
42import qualified Data.ByteString.Lazy as BL
42import qualified Data.ByteString.Lazy as BL
43−import Data.Maybe (fromMaybe)
43+import Data.Maybe (fromMaybe, isNothing)
44import Control.Monad (zipWithM)
44import Control.Monad (zipWithM)
45import Data.Aeson (ToJSON (..), encode)
45import Data.Aeson (ToJSON (..), encode)
46import Data.Char (chr, ord, isSpace)
46import Data.Char (chr, ord, isSpace)
@@ -394,8 +394,9 @@ toTableOfContents opts bs =
394-- | Converts an Element to a list item for a table of contents,
394-- | Converts an Element to a list item for a table of contents,
395sectionToListItem :: WriterOptions -> Block -> [Block]
395sectionToListItem :: WriterOptions -> Block -> [Block]
396sectionToListItem opts (Div (ident,_,_)
396sectionToListItem opts (Div (ident,_,_)
397− (Header lev (_,_,kvs) ils : subsecs)) =
397+ (Header lev (_,classes,kvs) ils : subsecs))
398+ | not (isNothing (lookup "number" kvs) && "unlisted" `elem` classes)
398− Plain headerLink : [BulletList listContents | not (null listContents)
399+ = Plain headerLink : [BulletList listContents | not (null listContents)
399 , lev < writerTOCDepth opts]
400 , lev < writerTOCDepth opts]
400 where
401 where
401 num = fromMaybe "" $ lookup "number" kvs
402 num = fromMaybe "" $ lookup "number" kvs
test/command/1762.mdnew file+18
@@ -0,0 +1,18 @@
1+```
2+% pandoc -t latex
3+# One {.unlisted}
4+
5+# Two {.unnumbered}
6+
7+# Three {.unlisted .unnumbered}
8+^D
9+\hypertarget{one}{%
10+\section{One}\label{one}}
11+
12+\hypertarget{two}{%
13+\section*{Two}\label{two}}
14+\addcontentsline{toc}{section}{Two}
15+
16+\hypertarget{three}{%
17+\section*{Three}\label{three}}
18+```