git.iko.soy/typeable/pandoc
on master help sign in
hierarchicalize: Do not number section with class "unnumbered".

Unnumbered sections get [] for their section number. So far only the HTML writer has been adjusted to be sensitive to this. If we keep this change, all the writers will need to be changed either (a) to directly check for the "unnumbered" class, if they do section numbering themselves, or (b) to check for a null section number, if they use hierarchicalize.

commitcdee226586c262a147c90b18e434d7fe8e02aaca authorJohn MacFarlane <fiddlosopher@gmail.com> dateWed 13 Feb 2013, 08:49 (14 years ago) parent1a22709
2 files changed+14−12
src/Text/Pandoc/Shared.hs+8−6 src/Text/Pandoc/Writers/HTML.hs+6−6
src/Text/Pandoc/Shared.hs+8−6
@@ -92,7 +92,7 @@ import Text.Pandoc.MIME (getMimeType)
9292import System.FilePath ( (</>), takeExtension, dropExtension )
9393import Data.Generics (Typeable, Data)
9494import qualified Control.Monad.State as S
95−import Control.Monad (msum)
95+import Control.Monad (msum, unless)
9696import Text.Pandoc.Pretty (charWidth)
9797import System.Locale (defaultTimeLocale)
9898import Data.Time
@@ -435,13 +435,15 @@ hierarchicalize blocks = S.evalState (hierarchicalizeWithIds blocks) []
435435
436436hierarchicalizeWithIds :: [Block] -> S.State [Int] [Element]
437437hierarchicalizeWithIds [] = return []
438−hierarchicalizeWithIds ((Header level attr title'):xs) = do
438+hierarchicalizeWithIds ((Header level attr@(_,classes,_) title'):xs) = do
439439 lastnum <- S.get
440440 let lastnum' = take level lastnum
441− let newnum = if length lastnum' >= level
442− then init lastnum' ++ [last lastnum' + 1]
443− else lastnum ++ replicate (level - length lastnum - 1) 0 ++ [1]
444− S.put newnum
441+ let newnum = case length lastnum' of
442+ x | "unnumbered" `elem` classes -> []
443+ | x >= level -> init lastnum' ++ [last lastnum' + 1]
444+ | otherwise -> lastnum ++
445+ replicate (level - length lastnum - 1) 0 ++ [1]
446+ unless (null newnum) $ S.put newnum
445447 let (sectionContents, rest) = break (headerLtEq level) xs
446448 sectionContents' <- hierarchicalizeWithIds sectionContents
447449 rest' <- hierarchicalizeWithIds rest
src/Text/Pandoc/Writers/HTML.hs+6−6
@@ -252,9 +252,9 @@ showSecNum = concat . intersperse "." . map show
252252elementToListItem :: WriterOptions -> Element -> State WriterState (Maybe Html)
253253elementToListItem opts (Sec lev num (id',classes,keyvals) headerText subsecs)
254254 | lev <= writerTOCDepth opts = do
255− let sectnum = if writerNumberSections opts
256− then (H.span ! A.class_ "toc-section-number" $ toHtml $ showSecNum num) >>
257− preEscapedString " "
255+ let sectnum = if writerNumberSections opts && not (null num)
256+ then (H.span ! A.class_ "toc-section-number"
257+ $ toHtml $ showSecNum num) >> preEscapedString " "
258258 else mempty
259259 txt <- liftM (sectnum >>) $ inlineListToHtml opts headerText
260260 subHeads <- mapM (elementToListItem opts) subsecs >>= return . catMaybes
@@ -453,9 +453,9 @@ blockToHtml opts (BlockQuote blocks) =
453453blockToHtml opts (Header level (ident,_,_) lst) = do
454454 contents <- inlineListToHtml opts lst
455455 secnum <- liftM stSecNum get
456− let contents' = if writerNumberSections opts
457− then (H.span ! A.class_ "header-section-number" $ toHtml $ showSecNum secnum) >>
458− strToHtml " " >> contents
456+ let contents' = if writerNumberSections opts && not (null secnum)
457+ then (H.span ! A.class_ "header-section-number" $ toHtml
458+ $ showSecNum secnum) >> strToHtml " " >> contents
459459 else contents
460460 let contents'' = if writerTableOfContents opts && not (null ident)
461461 then H.a ! A.href (toValue $