Skip to content

Commit

Permalink
Replace pandoc ref ID's to HTML ID's
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushalmodi committed Jul 19, 2018
1 parent c4251ab commit ac22a16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions ox-hugo-pandoc-cite.el
Expand Up @@ -79,23 +79,30 @@ Required fixes:
- Unescape the Hugo shortcodes: \"{{\\\\=< shortcode \\\\=>}}\" ->
\"{{< shortcode >}}\".
- Replace \"::: {#refs .references}\" with \"## References\" where the
number of hashes depends on HUGO_LEVEL_OFFSET.
- Replace \"::: {#refs .references}\" with \"## References\"
where the number of hashes depends on HUGO_LEVEL_OFFSET.
- Replace \"::: {#ref-someref} with \"<a id=\"ref-someref\"></a>\".
- Replace \"::: {#ref-someref}\" with \"<a
id=\"ref-someref\"></a>\".
- Remove \"^:::$\""
(with-temp-buffer
(insert content)
(let ((case-fold-search nil))
(goto-char (point-min))
(delete-matching-lines "^:::$")
;; Fix Hugo shortcodes.
(save-excursion
(let ((regexp (concat "{{\\\\<"
"\\(?1:\\(.\\|\n\\)+?\\)"
"\\\\>}}")))
(while (re-search-forward regexp nil :noerror)
(replace-match "{{<\\1>}}" :fixedcase))))
;; Convert Pandoc ref ID style to HTML ID's.
(save-excursion
(let ((regexp "^::: {#ref-\\(.+?\\)}$"))
(while (re-search-forward regexp nil :noerror)
(replace-match "<a id=\"ref-\\1\"></a>" :fixedcase))))
(buffer-substring-no-properties (point-min) (point-max)))))

(defun ox-hugo-pandoc-cite--parse-citations-maybe (info)
Expand Down
8 changes: 4 additions & 4 deletions test/site/content/posts/citations-example.md
Expand Up @@ -24,20 +24,20 @@ Content in section 2.
>}}
::: {#refs .references}
::: {#ref-eilan2016}
<a id="ref-eilan2016"></a>
Eilan, Naomi. 2016. "You Me and the World." *Analysis* 76 (3): 311--24.

::: {#ref-giovanelli2016}
<a id="ref-giovanelli2016"></a>
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.

::: {#ref-loncar2016}
<a id="ref-loncar2016"></a>
Loncar, Samuel. 2016. "Why Listen to Philosophers? A Constructive
Critique of Disciplinary Philosophy." *Metaphilosophy* 47 (1): 3--25.

::: {#ref-thompson2016}
<a id="ref-thompson2016"></a>
Thompson, Morgan, Toni Adleberg, Sam Sims, and Eddy Nahmias. 2016. "Why
Do Women Leave Philosophy? Surveying Students at the Introductory
Level."
Expand Down

0 comments on commit ac22a16

Please sign in to comment.