aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Shared.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-10-29 22:45:52 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-01-09 09:30:05 -0800
commitd599c4cdabd0d71fd9d27161c949b5e1e692436d (patch)
tree96b6130be929282f85d0261bbb0e0ef37e4e43ff /src/Text/Pandoc/Shared.hs
parent7a40fa8c08996cb94e7ff3cfafd8ede84972ce70 (diff)
downloadpandoc-d599c4cdabd0d71fd9d27161c949b5e1e692436d.tar.gz
Added Attr field to Header.
Previously header ids were autogenerated by the writers. Now they are generated (unless supplied explicitly) in the markdown parser, if the `header_identifiers` extension is selected. In addition, the textile reader now supports id attributes on headers.
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r--src/Text/Pandoc/Shared.hs19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 648086fd4..f23c043e1 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -426,18 +426,17 @@ inlineListToIdentifier =
-- | Convert list of Pandoc blocks into (hierarchical) list of Elements
hierarchicalize :: [Block] -> [Element]
-hierarchicalize blocks = S.evalState (hierarchicalizeWithIds blocks) ([],[])
+hierarchicalize blocks = S.evalState (hierarchicalizeWithIds blocks) []
-hierarchicalizeWithIds :: [Block] -> S.State ([Int],[String]) [Element]
+hierarchicalizeWithIds :: [Block] -> S.State [Int] [Element]
hierarchicalizeWithIds [] = return []
-hierarchicalizeWithIds ((Header level title'):xs) = do
- (lastnum, usedIdents) <- S.get
- let ident = uniqueIdent title' usedIdents
+hierarchicalizeWithIds ((Header level (ident,_,_) title'):xs) = do
+ lastnum <- S.get
let lastnum' = take level lastnum
let newnum = if length lastnum' >= level
then init lastnum' ++ [last lastnum' + 1]
else lastnum ++ replicate (level - length lastnum - 1) 0 ++ [1]
- S.put (newnum, (ident : usedIdents))
+ S.put newnum
let (sectionContents, rest) = break (headerLtEq level) xs
sectionContents' <- hierarchicalizeWithIds sectionContents
rest' <- hierarchicalizeWithIds rest
@@ -447,7 +446,7 @@ hierarchicalizeWithIds (x:rest) = do
return $ (Blk x) : rest'
headerLtEq :: Int -> Block -> Bool
-headerLtEq level (Header l _) = l <= level
+headerLtEq level (Header l _ _) = l <= level
headerLtEq _ _ = False
-- | Generate a unique identifier from a list of inlines.
@@ -466,15 +465,15 @@ uniqueIdent title' usedIdents =
-- | True if block is a Header block.
isHeaderBlock :: Block -> Bool
-isHeaderBlock (Header _ _) = True
+isHeaderBlock (Header _ _ _) = True
isHeaderBlock _ = False
-- | Shift header levels up or down.
headerShift :: Int -> Pandoc -> Pandoc
headerShift n = bottomUp shift
where shift :: Block -> Block
- shift (Header level inner) = Header (level + n) inner
- shift x = x
+ shift (Header level attr inner) = Header (level + n) attr inner
+ shift x = x
-- | Detect if a list is tight.
isTightList :: [[Block]] -> Bool