@@ -90,7 +90,7 @@ writeTEI opts (Pandoc meta blocks) = do
9090-- | Convert an Element to TEI.
9191elementToTEI :: PandocMonad m => WriterOptions -> Int -> Element -> m Doc
9292elementToTEI opts _ (Blk block) = blockToTEI opts block
93−elementToTEI opts lvl (Sec _ _num (id',_,_) title elements) = do
93+elementToTEI opts lvl (Sec _ _num attr title elements) = do
9494 -- TEI doesn't allow sections with no content, so insert some if needed
9595 let elements' = if null elements
9696 then [Blk (Para [])]
@@ -103,8 +103,7 @@ elementToTEI opts lvl (Sec _ _num (id',_,_) title elements) = do
103103 | otherwise -> "section"
104104 contents <- vcat <$> mapM (elementToTEI opts (lvl + 1)) elements'
105105 titleContents <- inlinesToTEI opts title
106− return $ inTags True "div" (("type", divType) :
107− [("xml:id", writerIdentifierPrefix opts ++ id') | not (null id')]) $
106+ return $ inTags True "div" (("type", divType) : idFromAttr opts attr) $
108107 inTagsSimple "head" titleContents $$ contents
109108
110109-- | Convert a list of Pandoc blocks to TEI.
@@ -142,8 +141,8 @@ listItemToTEI opts item =
142141 inTagsIndented "item" <$> blocksToTEI opts (map plainToPara item)
143142
144143imageToTEI :: PandocMonad m => WriterOptions -> Attr -> String -> m Doc
145−imageToTEI _ attr src = return $ selfClosingTag "graphic" $
146− ("url", src) : idAndRole attr ++ dims
144+imageToTEI opts attr src = return $ selfClosingTag "graphic" $
145+ ("url", src) : idFromAttr opts attr ++ dims
147146 where
148147 dims = go Width "width" ++ go Height "height"
149148 go dir dstr = case dimension dir attr of
@@ -155,8 +154,8 @@ blockToTEI :: PandocMonad m => WriterOptions -> Block -> m Doc
155154blockToTEI _ Null = return empty
156155-- Add ids to paragraphs in divs with ids - this is needed for
157156-- pandoc-citeproc to get link anchors in bibliographies:
158−blockToTEI opts (Div (ident,_,_) [Para lst]) = do
159− let attribs = [("xml:id", ident) | not (null ident)]
157+blockToTEI opts (Div attr [Para lst]) = do
158+ let attribs = idFromAttr opts attr
160159 inTags False "p" attribs <$> inlinesToTEI opts lst
161160blockToTEI opts (Div _ bs) = blocksToTEI opts $ map plainToPara bs
162161blockToTEI _ h@Header{} = do
@@ -320,8 +319,10 @@ inlineToTEI opts (Link attr txt (src, _))
320319 return $ linktext <+> char '(' <> emailLink <> char ')'
321320 | otherwise =
322321 (if "#" `isPrefixOf` src
323− then inTags False "ref" $ ("target", drop 1 src) : idAndRole attr
324− else inTags False "ref" $ ("target", src) : idAndRole attr ) <$>
322+ then inTags False "ref" $ ("target", drop 1 src)
323+ : idFromAttr opts attr
324+ else inTags False "ref" $ ("target", src)
325+ : idFromAttr opts attr ) <$>
325326 inlinesToTEI opts txt
326327inlineToTEI opts (Image attr description (src, tit)) = do
327328 let titleDoc = if null tit
@@ -337,12 +338,8 @@ inlineToTEI opts (Image attr description (src, tit)) = do
337338inlineToTEI opts (Note contents) =
338339 inTagsIndented "note" <$> blocksToTEI opts contents
339340
340−idAndRole :: Attr -> [(String, String)]
341−idAndRole (id',cls,_) = ident ++ role
342− where
343− ident = if null id'
344− then []
345− else [("xml:id", id')]
346− role = if null cls
347− then []
348− else [("role", unwords cls)]
341+idFromAttr :: WriterOptions -> Attr -> [(String, String)]
342+idFromAttr opts (id',_,_) =
343+ if null id'
344+ then []
345+ else [("xml:id", writerIdentifierPrefix opts ++ id')]