Don't use Pandoc inserted meta-data

Pandoc introduced its citations related meta-data like bibliography
and nocite which I did not prefer for few reasons:

1. It leaks full paths of the user's bibliography files in public.
2. Those meta-data fields are not needed by Hugo.
3. I like my style of YAML list fields better, it's more concise, and
   consistent with the YAML front-matter of non-Pandoc-Citation posts.
master
Kaushal Modi 8 years ago
parent eb85f26d78
commit e94c9d54b2
  1. 4
      doc/ox-hugo-manual.org
  2. 59
      ox-hugo-pandoc-cite.el
  3. 17
      ox-hugo.el
  4. 14
      test/site/content/posts/citations-example.md

@ -2077,8 +2077,8 @@ Pandoc based citation parsing is enabled by setting the
~#+hugo_pandoc_citations:~ keyword or ~:EXPORT_HUGO_PANDOC_CITATIONS:~
subtree property to ~t~. With this property set, the exported
front-matter is *forced to YAML*, because Pandoc needs the
front-matter to be in YAML format to parse fields like ~bibliography~
~csl~ and ~nocite~.
front-matter to be in YAML format to parse fields like ~csl~ and
~nocite~.
#+begin_note
User needs to have the ~pandoc~ executable present in their ~PATH~.

@ -12,19 +12,22 @@
;;; Code:
;; TODO: Change the defconst to defvar
(defconst ox-hugo-pandoc-cite-pandoc-args-list
(defvar ox-hugo-pandoc-cite-pandoc-args-list
'("--filter" "pandoc-citeproc"
"-f" "markdown"
"-t" "markdown-citations"
"--atx-headers" ;Use "# foo" style heading for output markdown
"--standalone") ;Include meta-data at the top
"Pandoc arguments used in `ox-hugo-pandoc-cite-run-pandoc'.
"--atx-headers") ;Use "# foo" style heading for output markdown
"Pandoc arguments used in `ox-hugo-pandoc-cite--run-pandoc'.
These arguments are added to the `pandoc' call in addition to the
\"--bibliography\", output file and input file arguments in that
function.")
(defun ox-hugo-pandoc-cite-run-pandoc (outfile bib-list)
(defvar ox-hugo-pandoc-cite-pandoc-meta-data
'("nocite" "csl")
"List of meta-data fields specific to Pandoc.")
(defun ox-hugo-pandoc-cite--run-pandoc (outfile bib-list)
"Run the `pandoc' process.
OUTFILE is the Org exported file name.
@ -55,22 +58,35 @@ BIB-LIST is a list of one or more bibliography files."
;; outfile) ;Input file
))
(defun ox-hugo-pandoc-cite--parse-citations-maybe (info outfile)
(defun ox-hugo-pandoc-cite--remove-pandoc-meta-data (fm)
"Remove Pandoc meta-data from front-matter string FM and return it.
The list of Pandoc specific meta-data is defined in
`ox-hugo-pandoc-cite-pandoc-meta-data'."
(with-temp-buffer
(insert fm)
(goto-char (point-min))
(dolist (field ox-hugo-pandoc-cite-pandoc-meta-data)
(let ((regexp (format "^%s: " (regexp-quote field))))
(delete-matching-lines regexp)))
(buffer-substring-no-properties
(point-min) (point-max))))
(defun ox-hugo-pandoc-cite--parse-citations-maybe (info)
"Check if Pandoc needs to be run to parse citations.
INFO is a plist used as a communication channel.
OUTFILE is the Org exported file name."
INFO is a plist used as a communication channel."
;; (message "pandoc citations keyword: %S"
;; (org-hugo--plist-get-true-p info :hugo-pandoc-citations))
;; (message "pandoc citations prop: %S"
;; (org-entry-get nil "EXPORT_HUGO_PANDOC_CITATIONS" :inherit))
(when (and outfile
(or (org-entry-get nil "EXPORT_HUGO_PANDOC_CITATIONS" :inherit)
(org-hugo--plist-get-true-p info :hugo-pandoc-citations)))
(unless (executable-find "pandoc")
(user-error "[ox-hugo] pandoc executable not found in PATH"))
(ox-hugo-pandoc-cite--parse-citations info outfile)))
(let ((outfile (plist-get info :outfile)))
(when (and outfile
(or (org-entry-get nil "EXPORT_HUGO_PANDOC_CITATIONS" :inherit)
(org-hugo--plist-get-true-p info :hugo-pandoc-citations)))
(unless (executable-find "pandoc")
(user-error "[ox-hugo] pandoc executable not found in PATH"))
(ox-hugo-pandoc-cite--parse-citations info outfile))))
(defun ox-hugo-pandoc-cite--parse-citations (info outfile)
"Parse Pandoc Citations in OUTFILE and update that file.
@ -111,7 +127,18 @@ OUTFILE is the Org exported file name."
fname))
bib-list-1)))))))
(if bib-list
(ox-hugo-pandoc-cite-run-pandoc outfile bib-list)
(let ((fm (plist-get info :front-matter)))
;; (message "fm :: %S" fm)
(ox-hugo-pandoc-cite--run-pandoc outfile bib-list)
;; Prepend the original ox-hugo generated front-matter to
;; Pandoc output.
(let* ((fm (ox-hugo-pandoc-cite--remove-pandoc-meta-data fm))
(post-pandoc-contents (with-temp-buffer
(insert-file-contents outfile)
(buffer-substring-no-properties
(point-min) (point-max))))
(fm-plus-content (concat fm "\n" post-pandoc-contents)))
(write-region fm-plus-content nil outfile)))
(message "[ox-hugo-pandoc-cite] No bibliography file was specified"))))

@ -125,6 +125,12 @@ helps set the bundle path correctly for such cases (where
EXPORT_HUGO_BUNDLE and EXPORT_FILE_NAME are set in the same
subtree).")
(defvar org-hugo--fm nil
"Variable to store the current Hugo post's front-matter string.
This variable is used to cache the original ox-hugo generated
front-matter that's used after Pandoc Citation parsing.")
(defvar org-hugo-allow-export-after-save t
"Enable flag for `org-hugo-export-wim-to-md-after-save'.
When nil, the above function will not export the Org file to
@ -965,7 +971,10 @@ This is an internal function."
(setq org-hugo--section nil)
(setq org-hugo--bundle nil)
(advice-remove 'org-babel-exp-code #'org-hugo--org-babel-exp-code)
(ox-hugo-pandoc-cite--parse-citations-maybe info outfile))
(plist-put info :outfile outfile)
(plist-put info :front-matter org-hugo--fm)
(ox-hugo-pandoc-cite--parse-citations-maybe info)
(setq org-hugo--fm nil))
;;;; HTMLized section number for headline
(defun org-hugo--get-headline-number (headline info &optional toc)
@ -2434,6 +2443,7 @@ INFO is a plist holding export options."
(body (if (org-string-nw-p body) ;Insert extra newline if body is non-empty
(format "\n%s" body)
"")))
(setq org-hugo--fm fm)
(format "%s%s%s" fm body org-hugo-footer)))
;;;;; Hugo Front Matter
@ -2775,9 +2785,8 @@ the Hugo front-matter."
INFO is a plist used as a communication channel."
;; (message "[hugo front matter DBG] info: %S" (pp info))
(let* ((fm-format (if (org-hugo--plist-get-true-p info :hugo-pandoc-citations)
;; pandoc-citations parses fields like
;; bibliography, csl and nocite from YAML
;; front-matter.
;; pandoc parses fields like csl and nocite
;; from YAML front-matter.
"yaml"
(plist-get info :hugo-front-matter-format)))
(author-list (and (plist-get info :with-author)

@ -1,15 +1,7 @@
---
bibliography:
- '/home/kmodi/stow/pub\_dotfiles/emacs/dot-emacs.d/elisp/ox-hugo/test/site/content-org/bib/bib1.bib'
- '/home/kmodi/stow/pub\_dotfiles/emacs/dot-emacs.d/elisp/ox-hugo/test/site/content-org/bib/bib2.bib'
draft: False
nocite:
- '@giovanelli2016'
- '@eilan2016'
tags:
- pandoc
- citeproc
title: Citations Example
title: "Citations Example"
tags: ["pandoc", "citeproc"]
draft: false
---
## Section 1

Loading…
Cancel
Save