From 128fb17c2b1fd29bbfbce868af1813ad35d31b2a Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Wed, 24 Jun 2026 10:22:55 -0700 Subject: [PATCH] markup/pandoc: Add citation support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #15062 Co-authored-by: Sebastian Höffner --- markup/pandoc/convert.go | 2 +- markup/pandoc/convert_integration_test.go | 97 ++++ markup/pandoc/testdata/foo.bib | 10 + markup/pandoc/testdata/ieee.csl | 512 ++++++++++++++++++++++ 4 files changed, 620 insertions(+), 1 deletion(-) create mode 100644 markup/pandoc/convert_integration_test.go create mode 100644 markup/pandoc/testdata/foo.bib create mode 100644 markup/pandoc/testdata/ieee.csl diff --git a/markup/pandoc/convert.go b/markup/pandoc/convert.go index 16c77d636..522307ee8 100644 --- a/markup/pandoc/convert.go +++ b/markup/pandoc/convert.go @@ -62,7 +62,7 @@ func (c *pandocConverter) getPandocContent(src []byte, ctx converter.DocumentCon if binaryName == "" { return nil, fmt.Errorf("pandoc not found in $PATH, cannot render %q", ctx.DocumentName) } - args := []string{"--mathjax"} + args := []string{"--mathjax", "--citeproc"} return internal.ExternallyRenderContent(c.cfg, ctx, src, binaryName, args) } diff --git a/markup/pandoc/convert_integration_test.go b/markup/pandoc/convert_integration_test.go new file mode 100644 index 000000000..47f1f1e95 --- /dev/null +++ b/markup/pandoc/convert_integration_test.go @@ -0,0 +1,97 @@ +// Copyright 2026 The Hugo Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package pandoc_test + +import ( + "testing" + + "github.com/gohugoio/hugo/hugolib" + "github.com/gohugoio/hugo/markup/pandoc" +) + +// See issue 15062. +func TestBibliographySupport(t *testing.T) { + if !pandoc.Supports() { + t.Skip("pandoc not installed") + } + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['home','rss','section','sitemap','taxonomy','term'] +[security.exec] +allow = ['pandoc'] +-- layouts/page.html -- +{{ .Content }} +-- content/p1.pdc -- +--- +title: home +--- + +--- +bibliography: testdata/foo.bib +citation-style: testdata/ieee.csl +link-citations: true +references: +- type: article-journal + id: WatsonCrick1953 + author: + - family: Watson + given: J. D. + - family: Crick + given: F. H. C. + issued: + date-parts: + - - 1953 + - 4 + - 25 + title: 'Molecular structure of nucleic acids: a structure for deoxyribose nucleic acid' + title-short: Molecular structure of nucleic acids + container-title: Nature + volume: 171 + issue: 4356 + page: 737-738 + DOI: 10.1038/171737a0 +--- + +This is a citation: @einstein1905physics + +This is another citation: [@WatsonCrick1953, p. 33] +` + + b := hugolib.Test(t, files) + + b.AssertFileContent("public/p1/index.html", + `

This is a citation: [1]

+

This is another citation: [2, p. 33]

+
+
[1]
A. +Einstein, “Zur elektrodynamik bewegter +körper,” Annalen der Physik, vol. 322, no. +10, pp. 891–921, 1905.
+
+
+
[2]
J. +D. Watson and F. H. C. Crick, “Molecular structure of nucleic +acids: a structure for deoxyribose nucleic acid,” +Nature, vol. 171, no. 4356, pp. 737–738, Apr. 1953, doi: 10.1038/171737a0.
+
+`, + ) +} diff --git a/markup/pandoc/testdata/foo.bib b/markup/pandoc/testdata/foo.bib new file mode 100644 index 000000000..d685cbb83 --- /dev/null +++ b/markup/pandoc/testdata/foo.bib @@ -0,0 +1,10 @@ +@article{einstein1905physics, + author = {Einstein, Albert}, + title = {Zur Elektrodynamik bewegter K{\"o}rper}, + journal = {Annalen der Physik}, + volume = {322}, + number = {10}, + pages = {891--921}, + year = {1905}, + publisher= {Wiley Online Library} +} diff --git a/markup/pandoc/testdata/ieee.csl b/markup/pandoc/testdata/ieee.csl new file mode 100644 index 000000000..80996195f --- /dev/null +++ b/markup/pandoc/testdata/ieee.csl @@ -0,0 +1,512 @@ + +