@@ -53,6 +53,13 @@ getStartLvl opts =
5353 TopLevelSection -> 1
5454 TopLevelDefault -> 1
5555
56+-- | Get correct name for the id attribute based on DocBook version.
57+-- DocBook 4 used custom id attribute but DocBook 5 adopted the xml:id specification.
58+-- https://www.w3.org/TR/xml-id/
59+idName :: DocBookVersion -> Text
60+idName DocBook5 = "xml:id"
61+idName DocBook4 = "id"
62+
5663-- | Convert list of authors to a docbook <author> section
5764authorToDocbook :: PandocMonad m => WriterOptions -> [Inline] -> DB m B.Inlines
5865authorToDocbook opts name' = do
@@ -174,10 +181,7 @@ blockToDocbook opts (Div (id',"section":_,_) (Header lvl _ ils : xs)) = do
174181 then "section"
175182 else "sect" <> tshow n
176183 _ -> "simplesect"
177− idName = if version == DocBook5
178− then "xml:id"
179− else "id"
180− idAttr = [(idName, writerIdentifierPrefix opts <> id') | not (T.null id')]
184+ idAttr = [(idName version, writerIdentifierPrefix opts <> id') | not (T.null id')]
181185 -- We want to add namespaces to the root (top-level) element.
182186 nsAttr = if version == DocBook5 && lvl == getStartLvl opts && isNothing (writerTemplate opts)
183187 -- Though, DocBook 4 does not support namespaces and
@@ -188,11 +192,12 @@ blockToDocbook opts (Div (id',"section":_,_) (Header lvl _ ils : xs)) = do
188192 title' <- inlinesToDocbook opts ils
189193 contents <- blocksToDocbook opts bs
190194 return $ inTags True tag attribs $ inTagsSimple "title" title' $$ contents
191−blockToDocbook opts (Div (ident,classes,_) bs) =
192− let identAttribs = [("id", ident) | not (T.null ident)]
195+blockToDocbook opts (Div (ident,classes,_) bs) = do
196+ version <- ask
197+ let identAttribs = [(idName version, ident) | not (T.null ident)]
193198 admonitions = ["attention","caution","danger","error","hint",
194199 "important","note","tip","warning"]
195− in case classes of
200+ case classes of
196201 (l:_) | l `elem` admonitions -> do
197202 let (mTitleBs, bodyBs) =
198203 case bs of
@@ -371,11 +376,12 @@ inlineToDocbook opts (Quoted _ lst) =
371376 inTagsSimple "quote" <$> inlinesToDocbook opts lst
372377inlineToDocbook opts (Cite _ lst) =
373378 inlinesToDocbook opts lst
374−inlineToDocbook opts (Span (ident,_,_) ils) =
379+inlineToDocbook opts (Span (ident,_,_) ils) = do
380+ version <- ask
375381 ((if T.null ident
376382 then mempty
377− else selfClosingTag "anchor" [("id", ident)]) <>) <$>
378− inlinesToDocbook opts ils
383+ else selfClosingTag "anchor" [(idName version, ident)]) <>) <$>
384+ inlinesToDocbook opts ils
379385inlineToDocbook _ (Code _ str) =
380386 return $ inTagsSimple "literal" $ literal (escapeStringForXML str)
381387inlineToDocbook opts (Math t str)