Skip to content

Commit

Permalink
Don't force the final front-matter to YAML because of Pandoc
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushalmodi committed Jul 19, 2018
1 parent c6949a5 commit 3dcec7e
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 20 deletions.
2 changes: 1 addition & 1 deletion ox-hugo-pandoc-cite.el
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The list of Pandoc specific meta-data is defined in
(insert fm)
(goto-char (point-min))
(dolist (field ox-hugo-pandoc-cite-pandoc-meta-data)
(let ((regexp (format "^%s: " (regexp-quote field))))
(let ((regexp (format "^%s\\(:\\| =\\) " (regexp-quote field))))
(delete-matching-lines regexp)))
(buffer-substring-no-properties (point-min) (point-max))))

Expand Down
33 changes: 24 additions & 9 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ subtree).")
This variable is used to cache the original ox-hugo generated
front-matter that's used after Pandoc Citation parsing.")

(defvar org-hugo--fm-yaml nil
"Variable to store the current Hugo post's front-matter string in YAML format.
Pandoc understands meta-data only in YAML format. So when Pandoc
Citations are enabled, Pandoc is handed over the file with this
YAML front-matter.")

(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
Expand Down Expand Up @@ -974,7 +981,8 @@ This is an internal function."
(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))
(setq org-hugo--fm nil)
(setq org-hugo--fm-yaml nil))

;;;; HTMLized section number for headline
(defun org-hugo--get-headline-number (headline info &optional toc)
Expand Down Expand Up @@ -2444,7 +2452,9 @@ INFO is a plist holding export options."
(format "\n%s" body)
"")))
(setq org-hugo--fm fm)
(format "%s%s%s" fm body org-hugo-footer)))
(if (org-hugo--plist-get-true-p info :hugo-pandoc-citations)
(format "%s%s%s" org-hugo--fm-yaml body org-hugo-footer)
(format "%s%s%s" fm body org-hugo-footer))))

;;;;; Hugo Front Matter
(defun org-hugo--quote-string (val &optional prefer-no-quotes format)
Expand Down Expand Up @@ -2784,11 +2794,7 @@ 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 parses fields like csl and nocite
;; from YAML front-matter.
"yaml"
(plist-get info :hugo-front-matter-format)))
(let* ((fm-format (plist-get info :hugo-front-matter-format))
(author-list (and (plist-get info :with-author)
(let ((author-raw
(org-string-nw-p
Expand Down Expand Up @@ -2956,7 +2962,8 @@ INFO is a plist used as a communication channel."
(blackfriday . ,blackfriday)
(menu . ,menu-alist)
(resources . ,resources)))
(data `,(append data weight-data custom-fm-data)))
(data `,(append data weight-data custom-fm-data))
ret)
;; (message "[get fm DBG] tags: %s" tags)
;; (message "dbg: hugo tags: %S" (plist-get info :hugo-tags))
;; (message "[get fm info DBG] %S" info)
Expand All @@ -2970,7 +2977,15 @@ INFO is a plist used as a communication channel."
;; (message "[fm categories DBG] %S" categories)
;; (message "[fm keywords DBG] %S" keywords)
(setq data (org-hugo--replace-keys-maybe data info))
(org-hugo--gen-front-matter data fm-format)))
(setq ret (org-hugo--gen-front-matter data fm-format))
(if (and (string= "toml" fm-format)
(org-hugo--plist-get-true-p info :hugo-pandoc-citations))
;; Pandoc parses fields like csl and nocite from YAML
;; front-matter. So create the `org-hugo--fm-yaml'
;; front-matter in YAML format just for Pandoc.
(setq org-hugo--fm-yaml (org-hugo--gen-front-matter data "yaml"))
(setq org-hugo--fm-yaml ret))
ret))

(defun org-hugo--calc-weight ()
"Calculate the weight for a Hugo post or menu item.
Expand Down
30 changes: 27 additions & 3 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -4591,17 +4591,17 @@ This post should also be created in =content/section-a/=.
#+include: "./all-posts.org::#nested-sections-example" :only-contents t
* Pandoc :pandoc:
** Citeproc :citeproc:
*** Citations Example
*** Citations Example (TOML) :toml:
:PROPERTIES:
:EXPORT_FILE_NAME: citations-example
:EXPORT_FILE_NAME: citations-example-toml
:EXPORT_HUGO_PANDOC_CITATIONS: t
:EXPORT_BIBLIOGRAPHY: bib/bib1.bib, bib/bib2.bib
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :nocite '(@giovanelli2016 @eilan2016)
:EXPORT_HUGO_PAIRED_SHORTCODES: %mdshortcode myshortcode
:END:
#+begin_description
Test the parsing of Pandoc Citations, while also testing that ox-hugo
exported Markdown doesn't get broken.
exported Markdown doesn't get broken -- TOML front-matter.
#+end_description
{{{oxhugoissue(175)}}}
**** Section 1
Expand Down Expand Up @@ -4634,6 +4634,30 @@ Text not containing *Markdown*
| a | b | c |
| d | e | f |
|----------+----------+----------|
*** Citations Example (YAML) :yaml:
:PROPERTIES:
:EXPORT_HUGO_FRONT_MATTER_FORMAT: yaml
:EXPORT_FILE_NAME: citations-example-yaml
:EXPORT_HUGO_PANDOC_CITATIONS: t
:EXPORT_BIBLIOGRAPHY: bib/bib1.bib, bib/bib2.bib
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :nocite '(@giovanelli2016 @eilan2016)
:END:
#+begin_description
Test the parsing of Pandoc Citations, while also testing that ox-hugo
exported Markdown doesn't get broken -- YAML front-matter.
#+end_description
{{{oxhugoissue(175)}}}
**** Section 1
Here is a test example file with an in-text citation where someone
important says something important (e.g. @loncar2016). And here is
another bit of blah with a footnote citation.[fn:5]

See [[#citation-example-section-2]].
**** Section 2
:PROPERTIES:
:CUSTOM_ID: citation-example-section-2
:END:
Content in section 2.
* Export Options :export_option:
** Table of Contents (TOC) :toc:
=ox-hugo= has the =with-toc= option disabled by default as Hugo has an
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
title: "Citations Example"
description: >
+++
title = "Citations Example (TOML)"
description = """
Test the parsing of Pandoc Citations, while also testing that ox-hugo
exported Markdown doesn't get broken.
tags: ["pandoc", "citeproc"]
draft: false
---
exported Markdown doesn't get broken -- TOML front-matter.
"""
tags = ["pandoc", "citeproc", "toml"]
draft = false
+++

`ox-hugo` Issue
\#[175](https://github.com/kaushalmodi/ox-hugo/issues/175)
Expand Down
68 changes: 68 additions & 0 deletions test/site/content/posts/citations-example-yaml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: "Citations Example (YAML)"
description: >
Test the parsing of Pandoc Citations, while also testing that ox-hugo
exported Markdown doesn't get broken -- YAML front-matter.
tags: ["pandoc", "citeproc", "yaml"]
draft: false
---

`ox-hugo` Issue
\#[175](https://github.com/kaushalmodi/ox-hugo/issues/175)

## Section 1

Here is a test example file with an in-text citation where someone
important says something important (e.g. Loncar (2016)). And here is
another bit of blah with a footnote citation.[^1]

See [Section 2](#citation-example-section-2).

## Section 2 {#citation-example-section-2}

Content in section 2.

## References {#references}

<div id="refs .references">
<div></div>


<div id="ref-eilan2016">
<div></div>

Eilan, Naomi. 2016. "You Me and the World." *Analysis* 76 (3): 311--24.

</div>

<div id="ref-giovanelli2016">
<div></div>

Giovanelli, Marco. 2016. "\"\...But I Still Can't Get Rid of a Sense of
Artificiality\" the Reichenbach--Einstein Debate on the Geometrization
of the Electromagnetic Field." *Studies in History and Philosophy of
Science* 54: 35--51.

</div>

<div id="ref-loncar2016">
<div></div>

Loncar, Samuel. 2016. "Why Listen to Philosophers? A Constructive
Critique of Disciplinary Philosophy." *Metaphilosophy* 47 (1): 3--25.

</div>

<div id="ref-thompson2016">
<div></div>

Thompson, Morgan, Toni Adleberg, Sam Sims, and Eddy Nahmias. 2016. "Why
Do Women Leave Philosophy? Surveying Students at the Introductory
Level."

</div>


</div> <!-- ending references -->

[^1]: See (Thompson et al. 2016).

0 comments on commit 3dcec7e

Please sign in to comment.