diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-07-21 20:47:18 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-07-21 20:47:18 -0700 |
commit | 5debb492ef64767677d893e2cf77a100d57796e0 (patch) | |
tree | 3d8596ed2d40fe4ccb20363b042f40726688ce1f | |
parent | 2a46042661a088096ac54097db5cd3674438bb63 (diff) | |
download | pandoc-5debb492ef64767677d893e2cf77a100d57796e0.tar.gz |
Revert "Shared.hierarchicalize: Don't number subsections of unnumbered sections."
This reverts commit 2a46042661a088096ac54097db5cd3674438bb63.
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 866fec674..bb13836f2 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -105,7 +105,7 @@ import System.FilePath ( (</>), takeExtension, dropExtension ) import Data.Generics (Typeable, Data) import qualified Control.Monad.State as S import qualified Control.Exception as E -import Control.Monad (msum) +import Control.Monad (msum, unless) import Text.Pandoc.Pretty (charWidth) import System.Locale (defaultTimeLocale) import Data.Time @@ -615,32 +615,25 @@ inlineListToIdentifier = -- | Convert list of Pandoc blocks into (hierarchical) list of Elements hierarchicalize :: [Block] -> [Element] -hierarchicalize blocks = S.evalState (hierarchicalizeWithIds True blocks) [] - -hierarchicalizeWithIds :: Bool -> [Block] -> S.State [Int] [Element] -hierarchicalizeWithIds _ [] = return [] -hierarchicalizeWithIds number ((Header level attr@(_,classes,_) title'):xs) = do - let number' = number && "unnumbered" `notElem` classes - newnum <- if number' - then do - lastnum <- S.get - let lastnum' = take level lastnum - let n = case length lastnum' of - x | x >= level -> init lastnum' ++ - [last lastnum' + 1] - | otherwise -> lastnum ++ - replicate (level - - length lastnum - 1) 0 ++ [1] - S.put n - return n - else return [] +hierarchicalize blocks = S.evalState (hierarchicalizeWithIds blocks) [] + +hierarchicalizeWithIds :: [Block] -> S.State [Int] [Element] +hierarchicalizeWithIds [] = return [] +hierarchicalizeWithIds ((Header level attr@(_,classes,_) title'):xs) = do + lastnum <- S.get + let lastnum' = take level lastnum + let newnum = case length lastnum' of + x | "unnumbered" `elem` classes -> [] + | x >= level -> init lastnum' ++ [last lastnum' + 1] + | otherwise -> lastnum ++ + replicate (level - length lastnum - 1) 0 ++ [1] + unless (null newnum) $ S.put newnum let (sectionContents, rest) = break (headerLtEq level) xs - -- ensure that subsections of an unnumbered section aren't numbered - sectionContents' <- hierarchicalizeWithIds number' sectionContents - rest' <- hierarchicalizeWithIds number rest + sectionContents' <- hierarchicalizeWithIds sectionContents + rest' <- hierarchicalizeWithIds rest return $ Sec level newnum attr title' sectionContents' : rest' -hierarchicalizeWithIds number (x:rest) = do - rest' <- hierarchicalizeWithIds number rest +hierarchicalizeWithIds (x:rest) = do + rest' <- hierarchicalizeWithIds rest return $ (Blk x) : rest' headerLtEq :: Int -> Block -> Bool |