git.iko.soy/typeable/pandoc
on master help sign in
DocBook writer: include an anchor element when a div or span has an id.

This closes #3102. Note that DocBook does not have a class attribute, but at least this provides an anchor for internal links.

commitfd4831dd03c8797af4bcb180dac775a08b7bf3d6 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 6 Sep 2016, 10:09 (10 years ago) parent09d96bb
1 file changed+9−2
src/Text/Pandoc/Writers/Docbook.hs+9−2
src/Text/Pandoc/Writers/Docbook.hs+9−2
@@ -176,7 +176,11 @@ blockToDocbook opts (Div (ident,_,_) [Para lst]) =
176176 then flush $ nowrap $ inTags False "literallayout" attribs
177177 $ inlinesToDocbook opts lst
178178 else inTags True "para" attribs $ inlinesToDocbook opts lst
179−blockToDocbook opts (Div _ bs) = blocksToDocbook opts $ map plainToPara bs
179+blockToDocbook opts (Div (ident,_,_) bs) =
180+ (if null ident
181+ then mempty
182+ else selfClosingTag "anchor" [("id", ident)]) $$
183+ blocksToDocbook opts (map plainToPara bs)
180184blockToDocbook _ (Header _ _ _) = empty -- should not occur after hierarchicalize
181185blockToDocbook opts (Plain lst) = inlinesToDocbook opts lst
182186-- title beginning with fig: indicates that the image is a figure
@@ -313,7 +317,10 @@ inlineToDocbook opts (Quoted _ lst) =
313317 inTagsSimple "quote" $ inlinesToDocbook opts lst
314318inlineToDocbook opts (Cite _ lst) =
315319 inlinesToDocbook opts lst
316−inlineToDocbook opts (Span _ ils) =
320+inlineToDocbook opts (Span (ident,_,_) ils) =
321+ (if null ident
322+ then mempty
323+ else selfClosingTag "anchor" [("id", ident)]) <>
317324 inlinesToDocbook opts ils
318325inlineToDocbook _ (Code _ str) =
319326 inTagsSimple "literal" $ text (escapeStringForXML str)