Browse Source

ox: Plug citations into export process

* lisp/ox.el (org-export-as): Add citation pre-processing.
Nicolas Goaziou 4 years ago
parent
commit
2c2b720394
1 changed files with 21 additions and 5 deletions
  1. 21 5
      lisp/ox.el

+ 21 - 5
lisp/ox.el

@@ -74,6 +74,8 @@
 
 
 (require 'cl-lib)
 (require 'cl-lib)
 (require 'ob-exp)
 (require 'ob-exp)
+(require 'oc)
+(require 'oc-basic)    ;default value for `org-cite-export-processors'
 (require 'ol)
 (require 'ol)
 (require 'org-element)
 (require 'org-element)
 (require 'org-macro)
 (require 'org-macro)
@@ -140,7 +142,9 @@
     (:with-tasks nil "tasks" org-export-with-tasks)
     (:with-tasks nil "tasks" org-export-with-tasks)
     (:with-timestamps nil "<" org-export-with-timestamps)
     (:with-timestamps nil "<" org-export-with-timestamps)
     (:with-title nil "title" org-export-with-title)
     (:with-title nil "title" org-export-with-title)
-    (:with-todo-keywords nil "todo" org-export-with-todo-keywords))
+    (:with-todo-keywords nil "todo" org-export-with-todo-keywords)
+    ;; Citations processing.
+    (:cite-export "CITE_EXPORT" nil org-cite-export-processors))
   "Alist between export properties and ways to set them.
   "Alist between export properties and ways to set them.
 
 
 The key of the alist is the property name, and the value is a list
 The key of the alist is the property name, and the value is a list
@@ -2988,6 +2992,10 @@ Return code as a string."
 	 (setq info
 	 (setq info
 	       (org-combine-plists
 	       (org-combine-plists
 		info (org-export-get-environment backend subtreep ext-plist)))
 		info (org-export-get-environment backend subtreep ext-plist)))
+         ;; Pre-process citations environment, i.e. install
+	 ;; bibliography list, and citation processor in INFO.
+	 (org-cite-store-bibliography info)
+         (org-cite-store-export-processor info)
 	 ;; De-activate uninterpreted data from parsed keywords.
 	 ;; De-activate uninterpreted data from parsed keywords.
 	 (dolist (entry (append (org-export-get-all-options backend)
 	 (dolist (entry (append (org-export-get-all-options backend)
 				org-export-options-alist))
 				org-export-options-alist))
@@ -3021,6 +3029,11 @@ Return code as a string."
 	 ;; Now tree is complete, compute its properties and add them
 	 ;; Now tree is complete, compute its properties and add them
 	 ;; to communication channel.
 	 ;; to communication channel.
 	 (setq info (org-export--collect-tree-properties tree info))
 	 (setq info (org-export--collect-tree-properties tree info))
+         ;; Process citations and bibliography.  Replace each citation
+	 ;; and "print_bibliography" keyword in the parse tree with
+	 ;; the output of the selected citation export processor.
+         (org-cite-process-citations info)
+         (org-cite-process-bibliography info)
 	 ;; Eventually transcode TREE.  Wrap the resulting string into
 	 ;; Eventually transcode TREE.  Wrap the resulting string into
 	 ;; a template.
 	 ;; a template.
 	 (let* ((body (org-element-normalize-string
 	 (let* ((body (org-element-normalize-string
@@ -3033,16 +3046,19 @@ Return code as a string."
 			      (funcall inner-template body info))
 			      (funcall inner-template body info))
 			    info))
 			    info))
 		(template (cdr (assq 'template
 		(template (cdr (assq 'template
-				     (plist-get info :translate-alist)))))
+				     (plist-get info :translate-alist))))
+                (output
+                 (if (or (not (functionp template)) body-only) full-body
+	           (funcall template full-body info))))
+           ;; Call citation export finalizer.
+           (setq output (org-cite-finalize-export output info))
 	   ;; Remove all text properties since they cannot be
 	   ;; Remove all text properties since they cannot be
 	   ;; retrieved from an external process.  Finally call
 	   ;; retrieved from an external process.  Finally call
 	   ;; final-output filter and return result.
 	   ;; final-output filter and return result.
 	   (org-no-properties
 	   (org-no-properties
 	    (org-export-filter-apply-functions
 	    (org-export-filter-apply-functions
 	     (plist-get info :filter-final-output)
 	     (plist-get info :filter-final-output)
-	     (if (or (not (functionp template)) body-only) full-body
-	       (funcall template full-body info))
-	     info))))))))
+	     output info))))))))
 
 
 ;;;###autoload
 ;;;###autoload
 (defun org-export-string-as (string backend &optional body-only ext-plist)
 (defun org-export-string-as (string backend &optional body-only ext-plist)