diff options
author | John MacFarlane <jgm@berkeley.edu> | 2013-01-11 17:07:25 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2013-01-11 17:07:25 -0800 |
commit | 98bc0d17ab3c31f53d7d133e3dc589fc93756c7b (patch) | |
tree | 08ca66fc0b7a54a2f4d624401f755bb1619ee6f6 | |
parent | f3f3638f21a5f9ca1c1933a969bdfc1aef1a2eb4 (diff) | |
download | pandoc-98bc0d17ab3c31f53d7d133e3dc589fc93756c7b.tar.gz |
Revised EPUB writer given changes in header attributes.
We need to ensure that all headers have attributes, since
this is no longer guaranteed by hierarchicalize.
Explicitly given headers remain the same.
-rw-r--r-- | src/Text/Pandoc/Writers/EPUB.hs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index 20b9f190d..389589e9a 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -119,7 +119,8 @@ writeEPUB opts doc@(Pandoc meta _) = do -- body pages -- add level 1 header to beginning if none there - let blocks' = case blocks of + let blocks' = addIdentifiers + $ case blocks of (Header 1 _ _ : _) -> blocks _ -> Header 1 ("",[],[]) (docTitle meta) : blocks @@ -431,6 +432,18 @@ data IdentState = IdentState{ showChapter :: Int -> String showChapter = printf "ch%03d.xhtml" +-- Add identifiers to any headers without them. +addIdentifiers :: [Block] -> [Block] +addIdentifiers bs = evalState (mapM go bs) [] + where go (Header n (ident,classes,kvs) ils) = do + ids <- get + let ident' = if null ident + then uniqueIdent ils ids + else ident + put $ ident' : ids + return $ Header n (ident',classes,kvs) ils + go x = return x + -- Go through a block list and construct a table -- correlating the automatically constructed references -- that would be used in a normal pandoc document with @@ -444,21 +457,19 @@ correlateRefs chapterHeaderLevel bs = , chapterIdents = [] , identTable = [] } where go :: Block -> State IdentState () - go (Header n _ ils) = do + go (Header n (ident,_,_) ils) = do when (n <= chapterHeaderLevel) $ modify $ \s -> s{ chapterNumber = chapterNumber s + 1 , chapterIdents = [] } st <- get - let runningid = uniqueIdent ils (runningIdents st) let chapterid = showChapter (chapterNumber st) ++ if n <= chapterHeaderLevel then "" else '#' : uniqueIdent ils (chapterIdents st) - modify $ \s -> s{ runningIdents = runningid : runningIdents st + modify $ \s -> s{ runningIdents = ident : runningIdents st , chapterIdents = chapterid : chapterIdents st - , identTable = (runningid, chapterid) : - identTable st - } + , identTable = (ident, chapterid) : identTable st + } go _ = return () -- Replace internal link references using the table produced |