From 0d06c632b10299d4955fc85c04c73c5796056891 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Thu, 30 Mar 2017 15:39:21 +0200
Subject: [PATCH] JATS writer: Fixed bibliography handling.

---
 src/Text/Pandoc/Writers/JATS.hs | 11 ++++++-----
 test/writer.jats                | 16 ++++++++++------
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/src/Text/Pandoc/Writers/JATS.hs b/src/Text/Pandoc/Writers/JATS.hs
index 9aaba78e0..5e1b3164b 100644
--- a/src/Text/Pandoc/Writers/JATS.hs
+++ b/src/Text/Pandoc/Writers/JATS.hs
@@ -181,11 +181,12 @@ listItemToJATS opts mbmarker item = do
 -- | Convert a Pandoc block element to JATS.
 blockToJATS :: PandocMonad m => WriterOptions -> Block -> DB m Doc
 blockToJATS _ Null = return empty
--- Add ids to paragraphs in divs with ids - this is needed for
--- pandoc-citeproc to get link anchors in bibliographies:
-blockToJATS opts (Div (ident,_,_) [Para lst]) =
-  let attribs = [("id", ident) | not (null ident)] in
-      inTags True "p" attribs <$> inlinesToJATS opts lst
+-- Bibliography reference:
+blockToJATS opts (Div ('r':'e':'f':'-':_,_,_) [Para lst]) =
+  inlinesToJATS opts lst
+blockToJATS opts (Div ("refs",_,_) xs) = do
+  contents <- blocksToJATS opts xs
+  return $ inTagsIndented "ref-list" contents
 blockToJATS opts (Div (ident,_,kvs) bs) = do
   contents <- blocksToJATS opts bs
   let attr = [("id", ident) | not (null ident)] ++
diff --git a/test/writer.jats b/test/writer.jats
index 1703de4aa..ae72133a8 100644
--- a/test/writer.jats
+++ b/test/writer.jats
@@ -893,9 +893,11 @@ These should not be escaped:  \$ \\ \&gt; \[ \{</preformat>
     </p>
     <boxed-text>
       <boxed-text>
-        <p>
-          foo
-        </p>
+        <boxed-text>
+          <p>
+            foo
+          </p>
+        </boxed-text>
       </boxed-text>
       <boxed-text>
         <p>
@@ -915,9 +917,11 @@ These should not be escaped:  \$ \\ \&gt; \[ \{</preformat>
     <p>
       Here’s a simple block:
     </p>
-    <p>
-      foo
-    </p>
+    <boxed-text>
+      <p>
+        foo
+      </p>
+    </boxed-text>
     <p>
       This should be a code block, though:
     </p>