Shared: Changed type of Element.

Sec now includes a field for Attr rather than just String
(the identifier).

Note, this is an API change.
This commit is contained in:
John MacFarlane 2013-02-12 20:13:23 -08:00
parent a49ecc9fe7
commit 5330e63421
6 changed files with 11 additions and 11 deletions

View file

@ -413,8 +413,8 @@ isPara _ = False
-- | Data structure for defining hierarchical Pandoc documents
data Element = Blk Block
| Sec Int [Int] String [Inline] [Element]
-- lvl num ident label contents
| Sec Int [Int] Attr [Inline] [Element]
-- lvl num attributes label contents
deriving (Eq, Read, Show, Typeable, Data)
-- | Convert Pandoc inline list to plain text identifier. HTML
@ -435,7 +435,7 @@ hierarchicalize blocks = S.evalState (hierarchicalizeWithIds blocks) []
hierarchicalizeWithIds :: [Block] -> S.State [Int] [Element]
hierarchicalizeWithIds [] = return []
hierarchicalizeWithIds ((Header level (ident,_,_) title'):xs) = do
hierarchicalizeWithIds ((Header level attr title'):xs) = do
lastnum <- S.get
let lastnum' = take level lastnum
let newnum = if length lastnum' >= level
@ -445,7 +445,7 @@ hierarchicalizeWithIds ((Header level (ident,_,_) title'):xs) = do
let (sectionContents, rest) = break (headerLtEq level) xs
sectionContents' <- hierarchicalizeWithIds sectionContents
rest' <- hierarchicalizeWithIds rest
return $ Sec level newnum ident title' sectionContents' : rest'
return $ Sec level newnum attr title' sectionContents' : rest'
hierarchicalizeWithIds (x:rest) = do
rest' <- hierarchicalizeWithIds rest
return $ (Blk x) : rest'

View file

@ -121,7 +121,7 @@ stringToConTeXt opts = concatMap (escapeCharForConTeXt opts)
-- | Convert Elements to ConTeXt
elementToConTeXt :: WriterOptions -> Element -> State WriterState Doc
elementToConTeXt _ (Blk block) = blockToConTeXt block
elementToConTeXt opts (Sec level _ id' title' elements) = do
elementToConTeXt opts (Sec level _ (id',_,_) title' elements) = do
header' <- sectionHeader id' level title'
innerContents <- mapM (elementToConTeXt opts) elements
return $ vcat (header' : innerContents)

View file

@ -94,7 +94,7 @@ writeDocbook opts (Pandoc (Meta tit auths dat) blocks) =
-- | Convert an Element to Docbook.
elementToDocbook :: WriterOptions -> Int -> Element -> Doc
elementToDocbook opts _ (Blk block) = blockToDocbook opts block
elementToDocbook opts lvl (Sec _ _num id' title elements) =
elementToDocbook opts lvl (Sec _ _num (id',_,_) title elements) =
-- Docbook doesn't allow sections with no content, so insert some if needed
let elements' = if null elements
then [Blk (Para [])]

View file

@ -230,7 +230,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
let navPointNode :: (Int -> String -> String -> [Element] -> Element)
-> Shared.Element -> State Int Element
navPointNode formatter (Sec _ nums ident ils children) = do
navPointNode formatter (Sec _ nums (ident,classes,keyvals) ils children) = do
n <- get
modify (+1)
let showNums :: [Int] -> String

View file

@ -250,7 +250,7 @@ showSecNum = concat . intersperse "." . map show
-- | Converts an Element to a list item for a table of contents,
-- retrieving the appropriate identifier from state.
elementToListItem :: WriterOptions -> Element -> State WriterState (Maybe Html)
elementToListItem opts (Sec lev num id' headerText subsecs)
elementToListItem opts (Sec lev num (id',classes,keyvals) headerText subsecs)
| lev <= writerTOCDepth opts = do
let sectnum = if writerNumberSections opts
then (H.span ! A.class_ "toc-section-number" $ toHtml $ showSecNum num) >>
@ -271,7 +271,7 @@ elementToListItem _ _ = return Nothing
-- | Convert an Element to Html.
elementToHtml :: Int -> WriterOptions -> Element -> State WriterState Html
elementToHtml _slideLevel opts (Blk block) = blockToHtml opts block
elementToHtml slideLevel opts (Sec level num id' title' elements) = do
elementToHtml slideLevel opts (Sec level num (id',classes,keyvals) title' elements) = do
let slide = writerSlideVariant opts /= NoSlides && level <= slideLevel
modify $ \st -> st{stSecNum = num} -- update section number
-- always use level 1 for slide titles

View file

@ -171,7 +171,7 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
-- | Convert Elements to LaTeX
elementToLaTeX :: WriterOptions -> Element -> State WriterState Doc
elementToLaTeX _ (Blk block) = blockToLaTeX block
elementToLaTeX opts (Sec level _ id' title' elements) = do
elementToLaTeX opts (Sec level _ (id',_,_) title' elements) = do
header' <- sectionHeader id' level title'
innerContents <- mapM (elementToLaTeX opts) elements
return $ vsep (header' : innerContents)
@ -236,7 +236,7 @@ toSlides bs = do
elementToBeamer :: Int -> Element -> State WriterState [Block]
elementToBeamer _slideLevel (Blk b) = return [b]
elementToBeamer slideLevel (Sec lvl _num ident tit elts)
elementToBeamer slideLevel (Sec lvl _num (ident,_,_) tit elts)
| lvl > slideLevel = do
bs <- concat `fmap` mapM (elementToBeamer slideLevel) elts
return $ Para ( RawInline "latex" "\\begin{block}{"