Docbook writer: Use correct id attribute consistently
DocBook5 should always use xml:id instead of id so let’s use it everywhere.
This commit is contained in:
parent
dc6856530c
commit
16ef877457
1 changed files with 16 additions and 10 deletions
|
@ -53,6 +53,13 @@ getStartLvl opts =
|
||||||
TopLevelSection -> 1
|
TopLevelSection -> 1
|
||||||
TopLevelDefault -> 1
|
TopLevelDefault -> 1
|
||||||
|
|
||||||
|
-- | Get correct name for the id attribute based on DocBook version.
|
||||||
|
-- DocBook 4 used custom id attribute but DocBook 5 adopted the xml:id specification.
|
||||||
|
-- https://www.w3.org/TR/xml-id/
|
||||||
|
idName :: DocBookVersion -> Text
|
||||||
|
idName DocBook5 = "xml:id"
|
||||||
|
idName DocBook4 = "id"
|
||||||
|
|
||||||
-- | Convert list of authors to a docbook <author> section
|
-- | Convert list of authors to a docbook <author> section
|
||||||
authorToDocbook :: PandocMonad m => WriterOptions -> [Inline] -> DB m B.Inlines
|
authorToDocbook :: PandocMonad m => WriterOptions -> [Inline] -> DB m B.Inlines
|
||||||
authorToDocbook opts name' = do
|
authorToDocbook opts name' = do
|
||||||
|
@ -174,10 +181,7 @@ blockToDocbook opts (Div (id',"section":_,_) (Header lvl _ ils : xs)) = do
|
||||||
then "section"
|
then "section"
|
||||||
else "sect" <> tshow n
|
else "sect" <> tshow n
|
||||||
_ -> "simplesect"
|
_ -> "simplesect"
|
||||||
idName = if version == DocBook5
|
idAttr = [(idName version, writerIdentifierPrefix opts <> id') | not (T.null id')]
|
||||||
then "xml:id"
|
|
||||||
else "id"
|
|
||||||
idAttr = [(idName, writerIdentifierPrefix opts <> id') | not (T.null id')]
|
|
||||||
-- We want to add namespaces to the root (top-level) element.
|
-- We want to add namespaces to the root (top-level) element.
|
||||||
nsAttr = if version == DocBook5 && lvl == getStartLvl opts && isNothing (writerTemplate opts)
|
nsAttr = if version == DocBook5 && lvl == getStartLvl opts && isNothing (writerTemplate opts)
|
||||||
-- Though, DocBook 4 does not support namespaces and
|
-- Though, DocBook 4 does not support namespaces and
|
||||||
|
@ -188,11 +192,12 @@ blockToDocbook opts (Div (id',"section":_,_) (Header lvl _ ils : xs)) = do
|
||||||
title' <- inlinesToDocbook opts ils
|
title' <- inlinesToDocbook opts ils
|
||||||
contents <- blocksToDocbook opts bs
|
contents <- blocksToDocbook opts bs
|
||||||
return $ inTags True tag attribs $ inTagsSimple "title" title' $$ contents
|
return $ inTags True tag attribs $ inTagsSimple "title" title' $$ contents
|
||||||
blockToDocbook opts (Div (ident,classes,_) bs) =
|
blockToDocbook opts (Div (ident,classes,_) bs) = do
|
||||||
let identAttribs = [("id", ident) | not (T.null ident)]
|
version <- ask
|
||||||
|
let identAttribs = [(idName version, ident) | not (T.null ident)]
|
||||||
admonitions = ["attention","caution","danger","error","hint",
|
admonitions = ["attention","caution","danger","error","hint",
|
||||||
"important","note","tip","warning"]
|
"important","note","tip","warning"]
|
||||||
in case classes of
|
case classes of
|
||||||
(l:_) | l `elem` admonitions -> do
|
(l:_) | l `elem` admonitions -> do
|
||||||
let (mTitleBs, bodyBs) =
|
let (mTitleBs, bodyBs) =
|
||||||
case bs of
|
case bs of
|
||||||
|
@ -371,11 +376,12 @@ inlineToDocbook opts (Quoted _ lst) =
|
||||||
inTagsSimple "quote" <$> inlinesToDocbook opts lst
|
inTagsSimple "quote" <$> inlinesToDocbook opts lst
|
||||||
inlineToDocbook opts (Cite _ lst) =
|
inlineToDocbook opts (Cite _ lst) =
|
||||||
inlinesToDocbook opts lst
|
inlinesToDocbook opts lst
|
||||||
inlineToDocbook opts (Span (ident,_,_) ils) =
|
inlineToDocbook opts (Span (ident,_,_) ils) = do
|
||||||
|
version <- ask
|
||||||
((if T.null ident
|
((if T.null ident
|
||||||
then mempty
|
then mempty
|
||||||
else selfClosingTag "anchor" [("id", ident)]) <>) <$>
|
else selfClosingTag "anchor" [(idName version, ident)]) <>) <$>
|
||||||
inlinesToDocbook opts ils
|
inlinesToDocbook opts ils
|
||||||
inlineToDocbook _ (Code _ str) =
|
inlineToDocbook _ (Code _ str) =
|
||||||
return $ inTagsSimple "literal" $ literal (escapeStringForXML str)
|
return $ inTagsSimple "literal" $ literal (escapeStringForXML str)
|
||||||
inlineToDocbook opts (Math t str)
|
inlineToDocbook opts (Math t str)
|
||||||
|
|
Loading…
Add table
Reference in a new issue