;;; ox-md-pandoc-zotero.el --- Export org citations to md and then to zotero formats via pandoc -*- lexical-binding: t; -*- ;; Copyright (C) 2021 Anders Johansson ;; Author: Anders Johansson ;; Created: 2021-06-23 ;; Modified: 2021-06-23 ;; Keywords: org, wp ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; ;;; Code: (require 'ox-md) (defgroup ox-md-pandoc-zotero nil "Customization for org export to zotero via pandoc md." :group 'org-export) (defcustom ox-md-pandoc-path-to-bbt-filter "" "Path to the betterbibtex pandoc filter for converting md to zotero odt/word. Latest file should be here: https://raw.githubusercontent.com/retorquere/zotero-better-bibtex/master/site/content/exporting/zotero.lua" :type 'file) (defcustom ox-md-pandoc-format "odt" "Final export format. odt or docx." :type '(choice (const "odt") (const "docx"))) (defcustom ox-md-pandoc-style "apa" "File to set in zotero output file. A valid csl style." :type 'string) (org-export-define-derived-backend 'md-pandoc-zotero 'md :menu-entry '(?p "MD→pandoc zotero export" ((?z "As zotero odt" ox-md-pandoc-zotero-odt)))) (defun ox-md-pandoc-zotero-odt (async subtreep visible-only body-only) "Export to md and then to odt with pandoc and zotero-better-bibtex filter." (interactive) (let ((outfile (org-export-output-file-name ".md" subtreep))) (org-export-to-file 'md outfile async subtreep visible-only body-only nil #'ox-md-pandoc-process-zotero-wpfile))) (defun ox-md-pandoc-process-zotero-wpfile (file) "Process markdown FILE to zotero odt or docx." (org-open-file (org-compile-file file (list (format "pandoc -s -o %%b.%s --lua-filter=%s --metadata=zotero_author_in_text=true --metadata=zotero_csl_style=%s %%f" ox-md-pandoc-format ox-md-pandoc-path-to-bbt-filter ox-md-pandoc-style)) ox-md-pandoc-format "See *ox-md-pandoc-zotero output* for details" (get-buffer-create "*ox-md-pandoc-zotero output*")))) (provide 'ox-md-pandoc-zotero) ;;; ox-md-pandoc-zotero.el ends here