@@ -90,7 +90,7 @@ writeTEI opts (Pandoc meta blocks) = do
90-- | Convert an Element to TEI.
90-- | Convert an Element to TEI.
91elementToTEI :: PandocMonad m => WriterOptions -> Int -> Element -> m Doc
91elementToTEI :: PandocMonad m => WriterOptions -> Int -> Element -> m Doc
92elementToTEI opts _ (Blk block) = blockToTEI opts block
92elementToTEI 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
94 -- TEI doesn't allow sections with no content, so insert some if needed
94 -- TEI doesn't allow sections with no content, so insert some if needed
95 let elements' = if null elements
95 let elements' = if null elements
96 then [Blk (Para [])]
96 then [Blk (Para [])]
@@ -103,8 +103,7 @@ elementToTEI opts lvl (Sec _ _num (id',_,_) title elements) = do
103 | otherwise -> "section"
103 | otherwise -> "section"
104 contents <- vcat <$> mapM (elementToTEI opts (lvl + 1)) elements'
104 contents <- vcat <$> mapM (elementToTEI opts (lvl + 1)) elements'
105 titleContents <- inlinesToTEI opts title
105 titleContents <- inlinesToTEI opts title
106− return $ inTags True "div" (("type", divType) :
106+ return $ inTags True "div" (("type", divType) : idFromAttr opts attr) $
107− [("xml:id", writerIdentifierPrefix opts ++ id') | not (null id')]) $
108 inTagsSimple "head" titleContents $$ contents
107 inTagsSimple "head" titleContents $$ contents
110-- | Convert a list of Pandoc blocks to TEI.
109-- | Convert a list of Pandoc blocks to TEI.
@@ -142,8 +141,8 @@ listItemToTEI opts item =
142 inTagsIndented "item" <$> blocksToTEI opts (map plainToPara item)
141 inTagsIndented "item" <$> blocksToTEI opts (map plainToPara item)
144imageToTEI :: PandocMonad m => WriterOptions -> Attr -> String -> m Doc
143imageToTEI :: PandocMonad m => WriterOptions -> Attr -> String -> m Doc
145−imageToTEI _ attr src = return $ selfClosingTag "graphic" $
144+imageToTEI opts attr src = return $ selfClosingTag "graphic" $
146− ("url", src) : idAndRole attr ++ dims
145+ ("url", src) : idFromAttr opts attr ++ dims
148 dims = go Width "width" ++ go Height "height"
147 dims = go Width "width" ++ go Height "height"
149 go dir dstr = case dimension dir attr of
148 go dir dstr = case dimension dir attr of
@@ -155,8 +154,8 @@ blockToTEI :: PandocMonad m => WriterOptions -> Block -> m Doc
155blockToTEI _ Null = return empty
154blockToTEI _ Null = return empty
156-- Add ids to paragraphs in divs with ids - this is needed for
155-- Add ids to paragraphs in divs with ids - this is needed for
157-- pandoc-citeproc to get link anchors in bibliographies:
156-- pandoc-citeproc to get link anchors in bibliographies:
158−blockToTEI opts (Div (ident,_,_) [Para lst]) = do
157+blockToTEI opts (Div attr [Para lst]) = do
159− let attribs = [("xml:id", ident) | not (null ident)]
158+ let attribs = idFromAttr opts attr
160 inTags False "p" attribs <$> inlinesToTEI opts lst
159 inTags False "p" attribs <$> inlinesToTEI opts lst
161blockToTEI opts (Div _ bs) = blocksToTEI opts $ map plainToPara bs
160blockToTEI opts (Div _ bs) = blocksToTEI opts $ map plainToPara bs
162blockToTEI _ h@Header{} = do
161blockToTEI _ h@Header{} = do
@@ -320,8 +319,10 @@ inlineToTEI opts (Link attr txt (src, _))
320 return $ linktext <+> char '(' <> emailLink <> char ')'
319 return $ linktext <+> char '(' <> emailLink <> char ')'
321 | otherwise =
320 | otherwise =
322 (if "#" `isPrefixOf` src
321 (if "#" `isPrefixOf` src
323− then inTags False "ref" $ ("target", drop 1 src) : idAndRole attr
322+ then inTags False "ref" $ ("target", drop 1 src)
323+ : idFromAttr opts attr
324− else inTags False "ref" $ ("target", src) : idAndRole attr ) <$>
324+ else inTags False "ref" $ ("target", src)
325+ : idFromAttr opts attr ) <$>
325 inlinesToTEI opts txt
326 inlinesToTEI opts txt
326inlineToTEI opts (Image attr description (src, tit)) = do
327inlineToTEI opts (Image attr description (src, tit)) = do
327 let titleDoc = if null tit
328 let titleDoc = if null tit
@@ -337,12 +338,8 @@ inlineToTEI opts (Image attr description (src, tit)) = do
337inlineToTEI opts (Note contents) =
338inlineToTEI opts (Note contents) =
338 inTagsIndented "note" <$> blocksToTEI opts contents
339 inTagsIndented "note" <$> blocksToTEI opts contents
340−idAndRole :: Attr -> [(String, String)]
341+idFromAttr :: WriterOptions -> Attr -> [(String, String)]
341−idAndRole (id',cls,_) = ident ++ role
342+idFromAttr opts (id',_,_) =
343− ident = if null id'
343+ if null id'
345− else [("xml:id", id')]
345+ else [("xml:id", writerIdentifierPrefix opts ++ id')]
348− else [("role", unwords cls)]