@@ -53,6 +53,13 @@ getStartLvl opts =
53 TopLevelSection -> 1
53 TopLevelSection -> 1
54 TopLevelDefault -> 1
54 TopLevelDefault -> 1
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"
56-- | Convert list of authors to a docbook <author> section
63-- | Convert list of authors to a docbook <author> section
57authorToDocbook :: PandocMonad m => WriterOptions -> [Inline] -> DB m B.Inlines
64authorToDocbook :: PandocMonad m => WriterOptions -> [Inline] -> DB m B.Inlines
58authorToDocbook opts name' = do
65authorToDocbook opts name' = do
@@ -174,10 +181,7 @@ blockToDocbook opts (Div (id',"section":_,_) (Header lvl _ ils : xs)) = do
174 then "section"
181 then "section"
175 else "sect" <> tshow n
182 else "sect" <> tshow n
176 _ -> "simplesect"
183 _ -> "simplesect"
177− idName = if version == DocBook5
180− idAttr = [(idName, writerIdentifierPrefix opts <> id') | not (T.null id')]
184+ idAttr = [(idName version, writerIdentifierPrefix opts <> id') | not (T.null id')]
181 -- We want to add namespaces to the root (top-level) element.
185 -- We want to add namespaces to the root (top-level) element.
182 nsAttr = if version == DocBook5 && lvl == getStartLvl opts && isNothing (writerTemplate opts)
186 nsAttr = if version == DocBook5 && lvl == getStartLvl opts && isNothing (writerTemplate opts)
183 -- Though, DocBook 4 does not support namespaces and
187 -- Though, DocBook 4 does not support namespaces and
@@ -188,11 +192,12 @@ blockToDocbook opts (Div (id',"section":_,_) (Header lvl _ ils : xs)) = do
188 title' <- inlinesToDocbook opts ils
192 title' <- inlinesToDocbook opts ils
189 contents <- blocksToDocbook opts bs
193 contents <- blocksToDocbook opts bs
190 return $ inTags True tag attribs $ inTagsSimple "title" title' $$ contents
194 return $ inTags True tag attribs $ inTagsSimple "title" title' $$ contents
191−blockToDocbook opts (Div (ident,classes,_) bs) =
195+blockToDocbook opts (Div (ident,classes,_) bs) = do
192− let identAttribs = [("id", ident) | not (T.null ident)]
197+ let identAttribs = [(idName version, ident) | not (T.null ident)]
193 admonitions = ["attention","caution","danger","error","hint",
198 admonitions = ["attention","caution","danger","error","hint",
194 "important","note","tip","warning"]
199 "important","note","tip","warning"]
195− in case classes of
200+ case classes of
196 (l:_) | l `elem` admonitions -> do
201 (l:_) | l `elem` admonitions -> do
197 let (mTitleBs, bodyBs) =
202 let (mTitleBs, bodyBs) =
198 case bs of
203 case bs of
@@ -371,11 +376,12 @@ inlineToDocbook opts (Quoted _ lst) =
371 inTagsSimple "quote" <$> inlinesToDocbook opts lst
376 inTagsSimple "quote" <$> inlinesToDocbook opts lst
372inlineToDocbook opts (Cite _ lst) =
377inlineToDocbook opts (Cite _ lst) =
373 inlinesToDocbook opts lst
378 inlinesToDocbook opts lst
374−inlineToDocbook opts (Span (ident,_,_) ils) =
379+inlineToDocbook opts (Span (ident,_,_) ils) = do
375 ((if T.null ident
381 ((if T.null ident
376 then mempty
382 then mempty
377− else selfClosingTag "anchor" [("id", ident)]) <>) <$>
383+ else selfClosingTag "anchor" [(idName version, ident)]) <>) <$>
378− inlinesToDocbook opts ils
384+ inlinesToDocbook opts ils
379inlineToDocbook _ (Code _ str) =
385inlineToDocbook _ (Code _ str) =
380 return $ inTagsSimple "literal" $ literal (escapeStringForXML str)
386 return $ inTagsSimple "literal" $ literal (escapeStringForXML str)
381inlineToDocbook opts (Math t str)
387inlineToDocbook opts (Math t str)