From ce002059a3d6e4a0066d41984c9931685615c952 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 6 Jun 2021 20:08:26 +0100 Subject: [PATCH] Pandoc - allow citeproc extension to be invoked, with bibliography. ref #8152 --- docs/data/docs.json | 5 +++++ markup/markup_config/config.go | 3 +++ markup/pandoc/convert.go | 13 ++++++++++- markup/pandoc/pandoc_config/config.go | 32 +++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 markup/pandoc/pandoc_config/config.go diff --git a/docs/data/docs.json b/docs/data/docs.json index 5e27712e361..31746676e98 100644 --- a/docs/data/docs.json +++ b/docs/data/docs.json @@ -1585,6 +1585,11 @@ "failureLevel": "fatal", "workingFolderCurrent": false, "preserveTOC": false + }, + "pandoc": { + "mathjax": true, + "citeproc": false + "bibliography": "data/bibliography.json" } }, "minify": { diff --git a/markup/markup_config/config.go b/markup/markup_config/config.go index a3562cd241f..428669cb28a 100644 --- a/markup/markup_config/config.go +++ b/markup/markup_config/config.go @@ -18,6 +18,7 @@ import ( "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/docshelper" "github.com/gohugoio/hugo/markup/asciidocext/asciidocext_config" + "github.com/gohugoio/hugo/markup/pandoc/pandoc_config" "github.com/gohugoio/hugo/markup/blackfriday/blackfriday_config" "github.com/gohugoio/hugo/markup/goldmark/goldmark_config" "github.com/gohugoio/hugo/markup/highlight" @@ -41,6 +42,7 @@ type Config struct { BlackFriday blackfriday_config.Config AsciidocExt asciidocext_config.Config + Pandoc pandoc_config.Config } func Decode(cfg config.Provider) (conf Config, err error) { @@ -114,6 +116,7 @@ var Default = Config{ BlackFriday: blackfriday_config.Default, AsciidocExt: asciidocext_config.Default, + Pandoc: pandoc_config.Default, } func init() { diff --git a/markup/pandoc/convert.go b/markup/pandoc/convert.go index 1c25e41d2d6..874f7f5a16f 100644 --- a/markup/pandoc/convert.go +++ b/markup/pandoc/convert.go @@ -53,6 +53,7 @@ func (c *pandocConverter) Supports(feature identity.Identity) bool { // getPandocContent calls pandoc as an external helper to convert pandoc markdown to HTML. func (c *pandocConverter) getPandocContent(src []byte, ctx converter.DocumentContext) []byte { + cfg := c.cfg.MarkupConfig.Pandoc logger := c.cfg.Logger path := getPandocExecPath() if path == "" { @@ -60,7 +61,17 @@ func (c *pandocConverter) getPandocContent(src []byte, ctx converter.DocumentCon " Leaving pandoc content unrendered.") return src } - args := []string{"--mathjax"} + args := []string{} + + if cfg.Mathjax { + args = append(args, "--mathjax") + } + + if cfg.Citeproc { + args = append(args, "--citeproc") + args = append(args, "--bibliography", cfg.Bibliography) + } + return internal.ExternallyRenderContent(c.cfg, ctx, src, path, args) } diff --git a/markup/pandoc/pandoc_config/config.go b/markup/pandoc/pandoc_config/config.go new file mode 100644 index 00000000000..47effbf3d15 --- /dev/null +++ b/markup/pandoc/pandoc_config/config.go @@ -0,0 +1,32 @@ +// Copyright 2021 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_config holds pandoc related configuration. +package pandoc_config + +var ( + // Default holds Hugo's default pandoc configuration. + Default = Config{ + Mathjax: true, + Citeproc: false, + Bibliography: "data/bibliography.json", + } + +) + +// Config configures asciidoc. +type Config struct { + Mathjax bool + Citeproc bool + Bibliography string +}