unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 2665dadfdb8a3622fcc490a6f177fd17e950eeed 23733 bytes (raw)
name: contrib/lisp/ox-jabref.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
 
;;; ox-jabref.el --- JabRef Citation Processor for Orgmode

;; Copyright (C) 2013 Jambunathan K <kjambunathan at gmail dot com>

;; Author: Jambunathan K <kjambunathan at gmail dot com>
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 8.0.6

;;; Commentary:

;;;; Quick start guide:
;;
;; 1. Install [[http://jabref.sourceforge.net/][JabRef]]
;;
;;    This module is tested with version JabRef-2.9.2.jar.
;;
;; 2. Install the JabRef plugin [[http://repo.or.cz/w/JabRefChicagoForOrgmode.git/blob_plain/HEAD:/net.sf.jabref.export.Chicago.ODF(English)-1.2.jar][Chicago Export filters for Org-mode]].
;;
;; 3. Configure ox-jabref.el
;;
;;    #+BEGIN_EXAMPLE
;;      M-x customize-group RET org-jabref RET
;;    #+END_EXAMPLE
;;
;;    Review the settings.
;;
;; 4. Configure ox-odt.el
;;
;;    #+BEGIN_EXAMPLE
;;      M-x customize-variable RET org-jabref-odt-citation-transcoders RET
;;    #+END_EXAMPLE
;;
;;    Following settings are recommended.
;;
;;    1. No citation support
;;
;;      #+BEGIN_SRC emacs-lisp
;;        (setq org-jabref-odt-citation-transcoders
;;              '(org-odt-latex-fragment . ignore))
;;      #+END_SRC
;;
;;      This is the default setting.
;;
;;       - #+BIBLIOGRAPHY is ignored.
;;       - \cite{} directives are typeset as plain text.

;;    2. Numeric Citations
;;
;;       #+BEGIN_SRC emacs-lisp
;;         (setq org-jabref-odt-citation-transcoders
;;               '(org-odt-citation-reference/numbered
;;                 . org-jabref-odt-bibliography/numbered))
;;       #+END_SRC
;;
;;       - #+BIBLIOGRAPHY is replaced with numerical listing of
;;         Bibliographic entries.  The listing includes only cited keys
;;         and is sorted on the order in which the cite keys are seen in
;;         the Org file.
;;
;;       - \cite{} directives are replaced with numeric links to the
;;         associated Bibliographic entry.
;;
;;    3. Unnumbered (or Text) Citations with Filtered Bibliography
;;
;;       #+BEGIN_SRC emacs-lisp
;;         (setq org-jabref-odt-citation-transcoders
;;               '(org-jabref-odt-citation-reference/text
;;               . org-jabref-odt-bibliography/filtered))
;;       #+END_SRC
;;
;;       - #+BIBLIOGRAPHY is replaced with listing of Bibliographic
;;         entries.  The listing is limited to just the cited keys.  The
;;         listing is sorted based on the order chosen by JabRef engine.
;;
;;       - \cite{} directives are replaced with textual links to the
;;         associated Bibliographic entry.
;;
;;    4. Unnumbered (or Text) Citations with Filtered Bibliography
;;
;;       #+BEGIN_SRC emacs-lisp
;;         (setq org-jabref-odt-citation-transcoders
;;               '(org-jabref-odt-citation-reference/text
;;               . org-jabref-odt-bibliography/unfiltered))
;;       #+END_SRC
;;
;;       - #+BIBLIOGRAPHY is replaced with listing of *all* Bibliographic
;;         entries.  The listing is limited to just the cited keys.  The
;;         listing is sorted based on the order chosen by JabRef engine.
;;
;;       - \cite{} directives are replaced with textual links to the
;;         associated Bibliographic entry.
;;
;;    5. Add the following line to your Org file and export.
;;
;;       #+BEGIN_SRC org
;;         ,#+BIBLIOGRAPHY: MyLibrary.bib
;;       #+END_SRC

;;;; Developer (or Implementation) notes
;;
;; The current #+BIBLIOGRAPHY is defined in contrib/lisp/ox-bibtex.el.
;; The syntax defined therein, is specific to a particular Citation
;; Processor (i.e., bibtex2html) and cannot be expected to be honored
;; by all backends AND citation processors[fn:1].
;;
;;   1. So having a "style" specification in a keyword line that is
;;      shared across all backends is absurd.[fn:2][fn:3].
;;
;;   2. It is unclear how well a "limit: " option can be honored by
;;      *ALL* citation processors.
;;
;; To keep things simple (and flexible), ox-jabref.el resorts to the
;; following:
;;
;;   1. *Always* use the first found style registered for the current
;;      backend in `org-jabref-export-formats'
;;
;;   2. "Limit"-ed (or non-"limit"-ed) export of Bibliographic entries
;;      can be achieved by using a different transcoder.  See "Quick
;;      start guide" above.
;;
;; Footnotes
;; ---------
;;
;; [fn:1] Note that the same Citation Processor (for example, JabRef)
;; can be used for catering to *both* HTML, ODT and even ASCII
;; backends.
;;
;; [fn:2] *If* one settles for Org-wide styles, a possible translation
;; from Org-specific style to Citation-specific style needs to be done
;; by each backend.  This is the sole purpose of
;; `org-jabref-export-formats'.
;;
;; Having an Org-wide styles is well-neigh impossible.  In that case,
;; the best option is to settle for a specification like
;;
;;    #+ATTR_HTML: :bib2html-style "plain"
;;    #+ATTR_ODT: :jabref-style "Chicago (author-date)"
;;    #+BIBLIOGRAPHY: MyLibrary.bib
;;
;; Note the keywords in #+ATTR_BACKEND lines are prefixed with the
;; Citation Processor.  This is important in light of earlier comments
;; [fn:1].
;;
;;; Code:

(require 'ox)
(require 'ox-odt)

;;; User Configuration Options.

(defgroup org-jabref nil
  "Options for processing citations via JabRef."
  :tag "Org Jabref"
  :group 'org-export)

(defcustom org-jabref-command '("java" "-jar" "JabRef-2.9.2.jar" "-n" "true")
  "Jabref program."
  :type '(choice
	  (const :tag "Not configured" nil)
	  (repeat string))
  :group 'org-jabref
  :version "24.4")

(defcustom org-jabref-export-formats
  '(("odt"
     ("Chicago Manual of Style (author-date)"
      :in-text "chicago.ODF.text" :bibliography "chicago.ODF.reference")))
  "JabRef export formats for various backends.
Each element in this list is of the form:

  \(EXPORT-BACKEND-NAME . BACKEND-STYLE-FITLERS\)

BACKEND-STYLE-FILTERS is of the form:

  \(CITATION-STYLE . EXPORT-FORMATS-PLIST\)

EXPORT-FORMATS-PLIST is property list with two well-known
properties - `:in-text' and `:bibliography'.  The values
of these properties are the export formats registered with
JabRef.

A typical value for this variable could be:

  '((\"odt\"
     (\"default\" :in-text \"chicago.ODF.text\"
      :bibliography \"chicago.ODF.reference\"))
    (\"html\"
     (\"default\" :bibliography \"html\")
     (\"simple\" :bibliography \"simplehtml\")))

For a list of export formats registered with JabRef use:

  java -jar JabRef-2.9.2.jar -n true -h."
  :group 'org-jabref
  :version "24.4"
  :type '(alist :key-type (string :tag "Export backend")
		:options ("odt" "html")
		:value-type
		(alist :key-type (string :tag "Citation style")
		       :options ("Chicago Manual of Style (author-date)")
		       :value-type
		       (plist :tag "export formats"
			      :value-type (string :tag "export format")
			      :options (:in-text
					:bibliography)))))

(defcustom org-jabref-export-formats
  '(("odt"
     ("Chicago Manual of Style (author-date)"
      :in-text "chicago.ODF.text" :bibliography "chicago.ODF.reference")))
  "JabRef export formats for various backends.
Each element in this list is of the form:

  \(EXPORT-BACKEND-NAME . BACKEND-STYLE-FITLERS\)

BACKEND-STYLE-FILTERS is of the form:

  \(CITATION-STYLE . EXPORT-FORMATS-PLIST\)

EXPORT-FORMATS-PLIST is property list with two well-known
properties - `:in-text' and `:bibliography'.  The values
of these properties are the export formats registered with
JabRef.

A typical value for this variable could be:

  '((\"odt\"
     (\"default\" :in-text \"chicago.ODF.text\"
      :bibliography \"chicago.ODF.reference\"))
    (\"html\"
     (\"default\" :bibliography \"html\")
     (\"simple\" :bibliography \"simplehtml\")))

For a list of export formats registered with JabRef use:

  java -jar JabRef-2.9.2.jar -n true -h."
  :group 'org-jabref
  :version "24.4"
  :type '(alist :key-type (string :tag "Export backend")
		:options ("odt" "html")
		:value-type
		(alist :key-type (string :tag "Citation style")
		       :options ("Chicago Manual of Style (author-date)")
		       :value-type
		       (plist :tag "export formats"
			      :value-type (string :tag "export format")
			      :options (:in-text
					:bibliography)))))

(defcustom org-jabref-odt-citation-transcoders
  '(org-odt-citation-reference/numbered . org-jabref-odt-bibliography/numbered)
  "Transcoders to handle citations.
Use CAR as the transcoder for CITATION-REFERENCE elements.  Use
CDR as the transcoder for BIBLIOGRAPHY.  See
`org-odt--translate-cite-fragments'.

For full citation support, install the required Citation
Processor (JabRef, for example) and turn on the associated Elisp
module in `org-modules'."
  :type `(cons
	  (radio :tag ,(format "%-35s" "Transcoder for \\cite{ } fragments")
		 (function-item :doc "Export Verbatim"
				org-odt-latex-fragment)
		 (function-item :doc "(JabRef) Enumerate"
				org-odt-citation-reference/numbered)
		 (function-item :doc "(JabRef) Text Description"
				org-jabref-odt-citation-reference/text)
		 function)
	  (radio :tag ,(format "%-35s" "Transcoder for Bibliography")
		 (function-item :doc "Strip Bibliography"
				ignore)
		 (function-item :doc "(JabRef) Enumerate, only cited entries, sort by reference"
				org-jabref-odt-bibliography/numbered)
		 (function-item :doc "(JabRef) Only cited entries, sort by reference"
				org-jabref-odt-bibliography/unnumbered)
		 (function-item :doc "(JabRef) Only cited entries, sort by application order"
				org-jabref-odt-bibliography/filtered)
		 (function-item :doc "(JabRef) Full bibliography, sort by application order"
				org-jabref-odt-bibliography/unfiltered)
		 function))
  :group 'org-export-odt
  :version "24.1")


\f
;;; Loading and Unloaing

(defvar org-jabref--stock-odt-backend
  (org-export-get-backend 'odt)
  "Backend definition of stock ODT exporter.")

(defvar org-jabref--enhanced-odt-backend
  (let* (;; Copy over the stock backend.
	 (enhanced-backend (copy-tree org-jabref--stock-odt-backend t)))
    ;; Override default citation transcoders with our own.
    (setf (org-export-backend-transcoders enhanced-backend)
	  (append
	   '((keyword . org-jabref-odt-keyword)
	     (citation-reference . org-jabref-odt-citation-reference))
	   (org-export-backend-transcoders org-jabref--stock-odt-backend)))
    ;; Modify the menu description.
    (let ((menu (org-export-backend-menu enhanced-backend)))
      (setf (cadr menu) (concat (cadr menu) " (With Jabref Processing)")))
    ;; Replace the existing ODT backend.
    (org-export-register-backend enhanced-backend)
    ;; Return the enhanced backend.
    enhanced-backend)
  "Backend definition of ODT exporter with JabRef processing.")

(defun ox-jabref-unload-function ()
  "Restore the stock ODT backend."
  (prog1 nil
    (org-export-register-backend org-jabref--stock-odt-backend)
    (message "ox-jabref: Unloaded")))

;;; Internal functions

(defun org-jabref--read-bibliography-attribute (info property)
  "Return value of PROPERTY of #+BIBLIOGRAPHY keyword.
INFO is a plist holding contextual information for purposes of
export.  PROPERTY is one of `:bib-file' or `:citation-style'.  If
it is neither, treat is as one of the properties in
#+ATTR_BACKEND attribute of #+BIBLIOGRAPHY keyword, where BACKEND
is the current export backend."
  (let* ((data (plist-get info :parse-tree))
	 (bibliography (org-element-map data 'keyword
			 (lambda (keyword)
			   (let ((key (org-element-property :key keyword)))
			     (and (string= (upcase key) "BIBLIOGRAPHY")
				  keyword)))
			 info 'first-match)))
    (cond
     ((memq property '(:bib-file :citation-style))
      (let* ((value (org-element-property :value bibliography))
     	     (values (split-string value))
     	     (attributes (list :bib-file
     			       (let ((bib-file (nth 0 values)))
     				 (concat (file-name-sans-extension bib-file)
					 ".bib"))
     			       :citation-style (nth 1 values))))
	(plist-get attributes property)))
     (t
      (let ((attribute (intern (format ":attr_%s" (plist-get info :backend)))))
	(org-export-read-attribute attribute bibliography property))))))

(defun org-jabref--get-export-format (info op)
  "Return the EXPORT-FORMAT configured for operation OP.
INFO is a plist holding contextual information.  OP can be one of
`:in-text' or `:bibliography'.  Return EXPORT-FORMAT is
that is registered for the current export backend.  See
`org-jabref-export-formats'."
  (let* ((backend (plist-get info :back-end))
	 (backend-name (symbol-name (org-export-backend-name backend)))
	 (styles-alist (assoc-default backend-name org-jabref-export-formats))
	 ;; FIXME: Ignore the "style" entry in "#+BIBLIOGRAPHY" line.
	 ;; Just go with the first registered style for this backend
	 ;; in `org-jabref-export-formats'.

	 ;; (citation-style (org-jabref--read-bibliography-attribute
	 ;; 		  info :citation-style))
	 (citation-style (caar styles-alist))
 	 ;; Get JabRef export format that match this backend and
	 ;; citation-style.
	 (export-formats-plist (assoc-default citation-style styles-alist)))
    (if (null op) export-formats-plist
      (plist-get export-formats-plist op))))

(defun org-jabref--run-cmd (&rest args)
  "Run JabRef command with ARGS.
Append ARGS to `org-jabref-command' and use `call-process'."
  (let ((cmd (append org-jabref-command args)))
    (let (exitcode err-string)
      (message "Running %s" (mapconcat 'identity cmd " "))
      (setq err-string
	    (with-output-to-string
	      (setq exitcode
		    (apply 'call-process (car cmd)
			   nil standard-output nil (cdr cmd)))))
      (or (zerop exitcode)
	  (error (format "JabRef command failed with error (%s)"
			 err-string))))))

(defun org-jabref--create-filtered-bibfile (bib-file cite-keys)
  "Truncate BIB-FILE so that it contains only CITE-KEYS.
Return name of the newly created bib file.

Specifically,

  - Create a temporary auxiliary file FILTERED.AUX file which
    contains just the CITE-KEYS

  - Run the following command (for example)

        jabref -n true -a FILTERED.AUX,FILTERED.BIB BIB-FILE

  - Return FILTERED.BIB."

  (let* ((aux-file (make-temp-file "jabref" nil ".aux"))
	 (filtered-bib-file (concat (file-name-sans-extension aux-file) ".bib")))
    ;; Create an .aux file out of CITE-KEYS.
    (with-current-buffer (find-file-noselect aux-file)
      (insert (mapconcat (lambda (cite-key)
			    (format "\\citation{%s}" cite-key))
			  cite-keys "\n"))
      (save-buffer 0))
    ;; Create a filtered bib file out of the aux file.
    (org-jabref--run-cmd "-a" (concat aux-file ","  filtered-bib-file) bib-file)
    ;; Delete aux file.
    (delete-file aux-file)
    ;; Return filtered bib file.
    filtered-bib-file))

;;;; Export a BIB file, enbloc

(defun org-jabref-export-bib-file (bib-file export-format)
  "Export BIB-FILE to EXPORT-FORMAT.
Return the resulting XML as string.  Specifically,

  - Run the following command (for example)

        jabref -n true -o OUT.XML,EXPORT-FORMAT BIB-FILE

  - Return contents of OUT.XML as a string."
  (when (and bib-file (file-readable-p bib-file) export-format)
    (with-demoted-errors
      (let* ((xml-file (make-temp-file "jabref-" nil ".xml")))
	;; Export the Citation to it's XML representation.
	(org-jabref--run-cmd "-o"  (concat xml-file "," export-format) bib-file)
	;; Return the XML string.
	(prog1 (with-temp-buffer
		 (insert-file-contents xml-file)
		 (buffer-string))
	  ;; Delete temporary xml file.
	  (delete-file xml-file))))))

(defun org-jabref-export-bib-file-with-filtering (bib-file cite-keys
							   export-format)
  "Export BIB-FILE to EXPORT-FORMAT, but limit output to just the CITE-KEYS.
Use `org-jabref--create-filtered-bibfile' and `org-jabref-export-bib-file'."
  (when (and bib-file (file-readable-p bib-file) cite-keys export-format)
    (let ((filtered-bib-file (org-jabref--create-filtered-bibfile bib-file
								  cite-keys)))
      (prog1 (org-jabref-export-bib-file filtered-bib-file export-format)
	(delete-file filtered-bib-file)))))

;;;; Export a CITE-KEY

(defun org-jabref-export-cite-key (bib-file cite-key export-format)
  "Export CITE-KEY from BIB-FILE to EXPORT-FORMAT.
Return the XML representation as a string. Specifically,

  - Run the following command (for example)

        jabref -n true -m CITE-KEY,OUT.XML,EXPORT-FORMAT BIB-FILE

  - Return contents of OUT.XML as a string."
  (when (and bib-file (file-readable-p bib-file) cite-key export-format)
    (with-demoted-errors
      (let* ((xml-file (file-name-nondirectory (make-temp-file "jabref-" nil
							       ".xml"))))
	;; Export the Citation to it's XML representation.
	(org-jabref--run-cmd "-m" (format "%s,%s,%s" cite-key xml-file
					  export-format) bib-file)
	;; Return the XML string.
	(prog1 (with-temp-buffer
		 (insert-file-contents xml-file)
		 (buffer-string))
	  ;; Delete temporary xml file.
	  (delete-file xml-file))))))

\f
;;; Transcoders

;;;; Bibliography

(defun org-jabref-odt-keyword (keyword contents info)
  "Transcode a KEYWORD element from Org to ODT.
CONTENTS is nil.  INFO is a plist holding contextual information.

If KEYWORD is a BIBLIOGRAPHY element, use the transcoder
specified in `org-jabref-odt-citation-transcoders'.  If no such
transcoder exists, return nil."
  (let ((key (org-element-property :key keyword))
	(value (org-element-property :value keyword)))
    (cond
     ;; Handle BIBLIOGRAPHY code.
     ((string= key "BIBLIOGRAPHY")
      (let* ((transcoder (cdr org-jabref-odt-citation-transcoders)))
	(when (and transcoder (fboundp transcoder))
	  (funcall transcoder keyword contents info))))
     ;; Keyword is other than BIBLIOGRAPHY.  Use the stock transcoder.
     (t (let ((transcoder (assoc-default 'keyword (org-export-backend-transcoders
						   org-jabref--stock-odt-backend))))
	  (funcall transcoder keyword contents info))))))


;;;; Bibliography :: Un-numbered

;;;###autoload
(defun org-jabref-odt-bibliography/unnumbered (bibliography contents info)
  "Transcode a BIBLIOGRAPHY element from Org to ODT.
CONTENTS is nil.  INFO is a plist holding contextual information.

Export each CITE-KEY in the parse tree through `:bibliography'
EXPORT-FORMAT.  Return the concatenated result, after adding some
separators."
  (let* ((bib-file (org-jabref--read-bibliography-attribute info :bib-file))
	 (cite-keys (mapcar 'car (plist-get info :citations-alist)))
	 (export-format (org-jabref--get-export-format info :bibliography)))
    (format "<text:section text:style-name=\"%s\" text:name=\"%s\">\n%s\n</text:section>"
	    "OrgIndexSection"
	    "Bibliography"
	    (concat (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
			    "Bibliography_20_Heading" "References")
		    (mapconcat
		     (lambda (cite-key)
		       (message "Generating BIBLIOGRAPHY entry for cite-key (%s)..."
				cite-key)
		       (org-jabref-export-cite-key bib-file cite-key
						   export-format))
		     cite-keys "\n")))))

;;;; Bibliography :: Numbered

;;;###autoload
(defun org-jabref-odt-bibliography/numbered (bibliography contents info)
  "Transcode a BIBLIOGRAPHY element from Org to ODT.
CONTENTS is nil.  INFO is a plist holding contextual information.

Export each CITE-KEY in the parse tree through `:bibliography'
EXPORT-FORMAT.  Enclose the entries in a numbered list and return
the result."
  (let* ((bib-file (org-jabref--read-bibliography-attribute info :bib-file))
	 ;; Reverse the entries in `:citation-alist' so that CITE-KEYs
	 ;; are sorted based on their order of occurrence in the Org
	 ;; file.
	 (cite-keys (reverse (mapcar 'car (plist-get info :citations-alist))))
	 (export-format (org-jabref--get-export-format info :bibliography)))
    ;; Enclose Bibliography in it's own section.
    (format
     "<text:section text:style-name=\"%s\" text:name=\"%s\">\n%s\n</text:section>"
     "OrgIndexSection"
     "Bibliography"
     (concat
      ;; Bibliography Heading
      (format "\n<text:p text:style-name=\"%s\">%s</text:p>" "Bibliography_20_Heading" "References")
      ;; Format Bibliography entries as a numbered list.
      (format
       "<text:list text:style-name=\"OrgBibliographyList\" text:continue-numbering=\"false\">%s</text:list>"
       (mapconcat
	(lambda (cite-key)
	  ;; Format each entry as a numbered item.
	  (format "\n<text:list-item>%s\n</text:list-item>"
		  (org-jabref-export-cite-key bib-file cite-key export-format)))
	cite-keys "\n"))))))

;;;; Bibliography :: Plain, Filtered

;;;###autoload
(defun org-jabref-odt-bibliography/filtered (bibliography contents info)
  "Transcode a BIBLIOGRAPHY element from Org to ODT.
CONTENTS is nil.  INFO is a plist holding contextual information.

Filter the BIB-FILE to just the cited entries.  Export the
filtered BIB-FILE through `:bibliography' EXPORT-FORMAT, return
the result as string."
  (let* ((bib-file (org-jabref--read-bibliography-attribute info :bib-file))
	 ;; Reverse the entries in `:citation-alist' so that CITE-KEYs
	 ;; are sorted based on their order of occurrence in the Org
	 ;; file.
	 (cite-keys (mapcar 'car (plist-get info :citations-alist)))
	 (export-format (org-jabref--get-export-format info :bibliography)))
    (message "Compiling BIBLIOGRAPHY (FILTERED)...")
    (format "<text:section text:style-name=\"%s\" text:name=\"%s\">\n%s\n</text:section>"
	    "OrgIndexSection"
	    "Bibliography"
	    (concat (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
			    "Bibliography_20_Heading" "References")
		    (org-jabref-export-bib-file-with-filtering
		     bib-file cite-keys export-format)))))

;;;; Bibliography :: Plain, Unfiltered

;;;###autoload
(defun org-jabref-odt-bibliography/unfiltered (bibliography contents info)
  "Transcode a BIBLIOGRAPHY element from Org to ODT.
CONTENTS is nil.  INFO is a plist holding contextual information.

Export the BIB-FILE through `:bibliography' EXPORT-FORMAT, return
the result as string."
  (let* ((bib-file (org-jabref--read-bibliography-attribute info :bib-file))
	 (export-format (org-jabref--get-export-format info :bibliography)))
    (message "Compiling BIBLIOGRAPHY UN-FILTERED" )
    (format "<text:section text:style-name=\"%s\" text:name=\"%s\">\n%s\n</text:section>"
	    "OrgIndexSection"
	    "Bibliography"
	    (concat (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
			    "Bibliography_20_Heading" "References")
		    (org-jabref-export-bib-file bib-file export-format)))))

;;;; Citation reference

(defun org-jabref-odt-citation-reference (citation-reference contents info)
  "Transcode a CITATION-REFERENCE element from Org to ODT.
CONTENTS is nil.  INFO is a plist holding contextual information."
  (let ((transcoder (car org-jabref-odt-citation-transcoders)))
    (when (and transcoder (fboundp transcoder))
      (funcall transcoder citation-reference contents info))))


;;;; Citation reference :: Plain Text (Author-Date etc.)

;;;###autoload
(defun org-jabref-odt-citation-reference/text (citation-reference contents info)
  "Transcode a CITATION-REFERENCE element from Org to ODT.
CONTENTS is nil.  INFO is a plist holding contextual information.

Pass each CITE-KEY from CITATION-REFERENCE in to `:in-text'
EXPORT-FORMAT.  Return the concatenated result, after adding some
separators."
  (let* ((latex-frag (org-element-property :value citation-reference))
	 (value (and (string-match "\\\\cite{\\(.*?\\)}" latex-frag)
		     (match-string 1 latex-frag)))
	 (cite-keys (org-split-string value ","))
	 (bib-file (org-jabref--read-bibliography-attribute info :bib-file))
	 (export-format (org-jabref--get-export-format info :in-text)))
    (mapconcat
     (lambda (cite-key)
       (message "Generating IN-TEXT entry for cite-key (%s)..." cite-key)
       (org-jabref-export-cite-key bib-file cite-key export-format))
     cite-keys ", ")))

(provide 'ox-jabref)

;;; ox-jabref.el ends here

debug log:

solving 2665dad ...
found 2665dad in https://yhetil.org/emacs-bugs/87txhmjouo.fsf@gmail.com/

applying [1/1] https://yhetil.org/emacs-bugs/87txhmjouo.fsf@gmail.com/
diff --git a/contrib/lisp/ox-jabref.el b/contrib/lisp/ox-jabref.el
new file mode 100644
index 0000000..2665dad

1:343: space before tab in indent.
     	     (values (split-string value))
1:344: space before tab in indent.
     	     (attributes (list :bib-file
1:345: space before tab in indent.
     			       (let ((bib-file (nth 0 values)))
1:346: space before tab in indent.
     				 (concat (file-name-sans-extension bib-file)
1:348: space before tab in indent.
     			       :citation-style (nth 1 values))))
Checking patch contrib/lisp/ox-jabref.el...
Applied patch contrib/lisp/ox-jabref.el cleanly.
warning: squelched 1 whitespace error
warning: 6 lines add whitespace errors.

index at:
100644 2665dadfdb8a3622fcc490a6f177fd17e950eeed	contrib/lisp/ox-jabref.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).