git.iko.soy/typeable/pandoc
on master help sign in
DocBook writer: add id to para if in Div with id element.

This makes the writer work properly with linked bibliographic items with pandoc-citeproc. Closes jgm/pandoc-citeproc#132.

commitf532dd69c9a4f9a3d408c7e502dc5417fe4949c2 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 20 May 2015, 10:55 (11 years ago) parent2fb5709
1 file changed+8
src/Text/Pandoc/Writers/Docbook.hs+8
src/Text/Pandoc/Writers/Docbook.hs+8
@@ -154,6 +154,14 @@ listItemToDocbook opts item =
154154-- | Convert a Pandoc block element to Docbook.
155155blockToDocbook :: WriterOptions -> Block -> Doc
156156blockToDocbook _ Null = empty
157+-- Add ids to paragraphs in divs with ids - this is needed for
158+-- pandoc-citeproc to get link anchors in bibliographies:
159+blockToDocbook opts (Div (ident,_,_) [Para lst]) =
160+ let attribs = [("id", ident) | not (null ident)] in
161+ if hasLineBreaks lst
162+ then flush $ nowrap $ inTags False "literallayout" attribs
163+ $ inlinesToDocbook opts lst
164+ else inTags True "para" attribs $ inlinesToDocbook opts lst
157165blockToDocbook opts (Div _ bs) = blocksToDocbook opts $ map plainToPara bs
158166blockToDocbook _ (Header _ _ _) = empty -- should not occur after hierarchicalize
159167blockToDocbook opts (Plain lst) = inlinesToDocbook opts lst