Skip to content

Commit b5c5a8b

Browse files
committed
Add configuration options for pandoc
Current options are: markup: pandoc: filters: - list - of - filters extensions: - list - of - extensions extraArgs: - --extra-arguments - --one-per-line Generalize some Pandoc options. Support configuring a bibliography in markup config Anonymous Update [pandoc] Allow page parameters to override site parameters. This allows specifying things like this in the page frontmatter: --- title: Something bibliography: source: mybibliography.bib pandoc: filter: - make-diagrams.lua ... These options are local to the page. Specifying the same under `markup` in the site configuration applies those settings to all pages. Paths (filters, bibliography, citation style) are resolved relative to the page, site, and the `static` folder. [pandoc] Support metadata Support specifying Pandoc metadata in the site configuration and page configuration using the following syntax: Site (in `config.yaml`): ```yaml markup: pandoc: metadata: link-citations: true ``` Or in frontmatter: ```yaml --- pandoc: metadata: link-citations: true ... ``` [pandoc] Simplify path management. No need for any fancy path lookup gymnastics. `pandoc`'s `--resource-path` option does the legwork of locating resources on multiple directories. [pandoc] Don't use x != "" to denote failure.
1 parent c9e6790 commit b5c5a8b

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

Diff for: markup/markup_config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,6 @@ var Default = Config{
111111
Bibliography: bibliography.Default,
112112

113113
Goldmark: goldmark_config.Default,
114+
Pandoc: pandoc_config.Default,
114115
AsciidocExt: asciidocext_config.Default,
115116
}

Diff for: markup/pandoc/convert.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
package pandoc
1616

1717
import (
18+
"errors"
1819
"strings"
1920

2021
"github.com/gohugoio/hugo/common/hexec"
2122
"github.com/gohugoio/hugo/htesting"
2223
"github.com/mitchellh/mapstructure"
2324

2425
"github.com/gohugoio/hugo/identity"
25-
2626
"github.com/gohugoio/hugo/markup/bibliography"
2727
"github.com/gohugoio/hugo/markup/converter"
2828
"github.com/gohugoio/hugo/markup/internal"
@@ -64,7 +64,7 @@ type pandocConverter struct {
6464
}
6565

6666
func (c *pandocConverter) Convert(ctx converter.RenderContext) (converter.ResultRender, error) {
67-
b, err := c.getPandocContent(ctx.Src, c.ctx)
67+
b, err := c.getPandocContent(ctx.Src)
6868
if err != nil {
6969
return nil, err
7070
}
@@ -76,17 +76,14 @@ func (c *pandocConverter) Supports(feature identity.Identity) bool {
7676
}
7777

7878
// getPandocContent calls pandoc as an external helper to convert pandoc markdown to HTML.
79-
func (c *pandocConverter) getPandocContent(src []byte) []byte {
80-
logger := c.cfg.Logger
79+
func (c *pandocConverter) getPandocContent(src []byte) ([]byte, error) {
8180
pandocPath, pandocFound := getPandocBinaryName()
8281
if !pandocFound {
83-
logger.Println("pandoc not found in $PATH: Please install.\n",
84-
" Leaving pandoc content unrendered.")
85-
return src
82+
return nil, errors.New("pandoc not found in $PATH: Please install.")
8683
}
8784

88-
var pandocConfig pandoc_config.Config = c.cfg.MarkupConfig.Pandoc
89-
var bibConfig bibliography.Config = c.cfg.MarkupConfig.Bibliography
85+
var pandocConfig pandoc_config.Config = c.cfg.MarkupConfig().Pandoc
86+
var bibConfig bibliography.Config = c.cfg.MarkupConfig().Bibliography
9087

9188
if pageParameters, ok := c.docCtx.Document.(paramer); ok {
9289
if bibParam, err := pageParameters.Param("bibliography"); err == nil {
@@ -111,7 +108,7 @@ func (c *pandocConverter) getPandocContent(src []byte) []byte {
111108
arguments = append(arguments, "--resource-path", resourcePath)
112109

113110
renderedContent, _ := internal.ExternallyRenderContent(c.cfg, c.docCtx, src, pandocPath, arguments)
114-
return renderedContent
111+
return renderedContent, nil
115112
}
116113

117114
const pandocBinary = "pandoc"

Diff for: markup/pandoc/pandoc_config/pandoc.go

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ type Config struct {
6969
ExtraArgs []string
7070
}
7171

72+
var Default = Config{
73+
InputFormat: "markdown",
74+
UseLegacyHtml: false,
75+
UseMathjax: true,
76+
}
77+
7278
func (c *Config) getInputArg() string {
7379
var b strings.Builder
7480
b.WriteString("--from=")

0 commit comments

Comments
 (0)