Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pandoc - allow citeproc extension to be invoked, with bibliography. #8610

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/data/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,11 @@
"failureLevel": "fatal",
"workingFolderCurrent": false,
"preserveTOC": false
},
"pandoc": {
"mathjax": true,
"citeproc": false
"bibliography": "data/bibliography.json"
}
},
"mergeStrategy": {
Expand Down
3 changes: 3 additions & 0 deletions markup/markup_config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -40,6 +41,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) {
Expand Down Expand Up @@ -113,6 +115,7 @@ var Default = Config{
BlackFriday: blackfriday_config.Default,

AsciidocExt: asciidocext_config.Default,
Pandoc: pandoc_config.Default,
}

func init() {
Expand Down
13 changes: 12 additions & 1 deletion markup/pandoc/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,25 @@ 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 == "" {
logger.Println("pandoc not found in $PATH: Please install.\n",
" 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)
}

Expand Down
32 changes: 32 additions & 0 deletions markup/pandoc/pandoc_config/config.go
Original file line number Diff line number Diff line change
@@ -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
}