aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-09-06 10:09:52 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2016-09-06 10:09:52 +0200
commitfd4831dd03c8797af4bcb180dac775a08b7bf3d6 (patch)
treed3051a70583b7bc98bd9d2c033dbf82f02dbe4db
parent09d96bb88492a8a26a7ed22c40b044b1a63d520d (diff)
downloadpandoc-fd4831dd03c8797af4bcb180dac775a08b7bf3d6.tar.gz
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.
-rw-r--r--src/Text/Pandoc/Writers/Docbook.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Docbook.hs b/src/Text/Pandoc/Writers/Docbook.hs
index 9b1c70166..8bb0810e4 100644
--- a/src/Text/Pandoc/Writers/Docbook.hs
+++ b/src/Text/Pandoc/Writers/Docbook.hs
@@ -176,7 +176,11 @@ blockToDocbook opts (Div (ident,_,_) [Para lst]) =
then flush $ nowrap $ inTags False "literallayout" attribs
$ inlinesToDocbook opts lst
else inTags True "para" attribs $ inlinesToDocbook opts lst
-blockToDocbook opts (Div _ bs) = blocksToDocbook opts $ map plainToPara bs
+blockToDocbook opts (Div (ident,_,_) bs) =
+ (if null ident
+ then mempty
+ else selfClosingTag "anchor" [("id", ident)]) $$
+ blocksToDocbook opts (map plainToPara bs)
blockToDocbook _ (Header _ _ _) = empty -- should not occur after hierarchicalize
blockToDocbook opts (Plain lst) = inlinesToDocbook opts lst
-- title beginning with fig: indicates that the image is a figure
@@ -313,7 +317,10 @@ inlineToDocbook opts (Quoted _ lst) =
inTagsSimple "quote" $ inlinesToDocbook opts lst
inlineToDocbook opts (Cite _ lst) =
inlinesToDocbook opts lst
-inlineToDocbook opts (Span _ ils) =
+inlineToDocbook opts (Span (ident,_,_) ils) =
+ (if null ident
+ then mempty
+ else selfClosingTag "anchor" [("id", ident)]) <>
inlinesToDocbook opts ils
inlineToDocbook _ (Code _ str) =
inTagsSimple "literal" $ text (escapeStringForXML str)