From 051b7ffeaffdaf34ed1384a239cf0179aa59b932 Mon Sep 17 00:00:00 2001
From: Albert Krewinkel <albert@zeitkraut.de>
Date: Sat, 10 Apr 2021 10:47:10 +0200
Subject: [PATCH] JATS writer: add footnote number as label in backmatter

Footnotes in the backmatter are given the footnote's number as a label.
The articleauthoring output is unaffected from this change, as footnotes
are placed inline there.

Closes: #7210
---
 src/Text/Pandoc/Writers/JATS.hs |  1 +
 test/writer.jats_archiving      | 14 ++++++++------
 test/writer.jats_publishing     | 14 ++++++++------
 3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/Text/Pandoc/Writers/JATS.hs b/src/Text/Pandoc/Writers/JATS.hs
index 26f94cb03..e78c6dc8f 100644
--- a/src/Text/Pandoc/Writers/JATS.hs
+++ b/src/Text/Pandoc/Writers/JATS.hs
@@ -436,6 +436,7 @@ inlineToJATS opts (Note contents) = do
                       (n, _):_ -> n + 1
                       []       -> 1
       thenote <- inTags True "fn" [("id", "fn" <> tshow notenum)]
+                     . (inTagsSimple "label" (literal $ tshow notenum) <>)
                     <$> wrappedBlocksToJATS (not . isPara) opts
                          (walk demoteHeaderAndRefs contents)
       modify $ \st -> st{ jatsNotes = (notenum, thenote) : notes }
diff --git a/test/writer.jats_archiving b/test/writer.jats_archiving
index 1a9537a21..332b5d3fd 100644
--- a/test/writer.jats_archiving
+++ b/test/writer.jats_archiving
@@ -882,11 +882,12 @@ These should not be escaped:  \$ \\ \&gt; \[ \{</preformat>
 <back>
 <fn-group>
   <fn id="fn1">
-    <p>Here is the footnote. It can go anywhere after the footnote reference.
-    It need not be placed at the end of the document.</p>
+    <label>1</label><p>Here is the footnote. It can go anywhere after the
+    footnote reference. It need not be placed at the end of the document.</p>
   </fn>
   <fn id="fn2">
-    <p>Here’s the long note. This one contains multiple blocks.</p>
+    <label>2</label><p>Here’s the long note. This one contains multiple
+    blocks.</p>
     <p>Subsequent blocks are indented to show that they belong to the footnote
     (as with list items).</p>
     <p specific-use="wrapper">
@@ -896,16 +897,17 @@ These should not be escaped:  \$ \\ \&gt; \[ \{</preformat>
     just indent the first line of each block.</p>
   </fn>
   <fn id="fn3">
-    <p>This is <italic>easier</italic> to type. Inline notes may contain
+    <label>3</label><p>This is <italic>easier</italic> to type. Inline notes
+    may contain
     <ext-link ext-link-type="uri" xlink:href="http://google.com">links</ext-link>
     and <monospace>]</monospace> verbatim characters, as well as [bracketed
     text].</p>
   </fn>
   <fn id="fn4">
-    <p>In quote.</p>
+    <label>4</label><p>In quote.</p>
   </fn>
   <fn id="fn5">
-    <p>In list.</p>
+    <label>5</label><p>In list.</p>
   </fn>
 </fn-group>
 </back>
diff --git a/test/writer.jats_publishing b/test/writer.jats_publishing
index b85816848..f53fd554d 100644
--- a/test/writer.jats_publishing
+++ b/test/writer.jats_publishing
@@ -882,11 +882,12 @@ These should not be escaped:  \$ \\ \&gt; \[ \{</preformat>
 <back>
 <fn-group>
   <fn id="fn1">
-    <p>Here is the footnote. It can go anywhere after the footnote reference.
-    It need not be placed at the end of the document.</p>
+    <label>1</label><p>Here is the footnote. It can go anywhere after the
+    footnote reference. It need not be placed at the end of the document.</p>
   </fn>
   <fn id="fn2">
-    <p>Here’s the long note. This one contains multiple blocks.</p>
+    <label>2</label><p>Here’s the long note. This one contains multiple
+    blocks.</p>
     <p>Subsequent blocks are indented to show that they belong to the footnote
     (as with list items).</p>
     <p specific-use="wrapper">
@@ -896,16 +897,17 @@ These should not be escaped:  \$ \\ \&gt; \[ \{</preformat>
     just indent the first line of each block.</p>
   </fn>
   <fn id="fn3">
-    <p>This is <italic>easier</italic> to type. Inline notes may contain
+    <label>3</label><p>This is <italic>easier</italic> to type. Inline notes
+    may contain
     <ext-link ext-link-type="uri" xlink:href="http://google.com">links</ext-link>
     and <monospace>]</monospace> verbatim characters, as well as [bracketed
     text].</p>
   </fn>
   <fn id="fn4">
-    <p>In quote.</p>
+    <label>4</label><p>In quote.</p>
   </fn>
   <fn id="fn5">
-    <p>In list.</p>
+    <label>5</label><p>In list.</p>
   </fn>
 </fn-group>
 </back>