From b5c5a8bd761acd9d7295b3cb2c05df18d73f6bba Mon Sep 17 00:00:00 2001 From: Asanka Herath Date: Sat, 18 Jul 2020 15:21:51 -0400 Subject: [PATCH] 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. --- markup/markup_config/config.go | 1 + markup/pandoc/convert.go | 17 +++++++---------- markup/pandoc/pandoc_config/pandoc.go | 6 ++++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/markup/markup_config/config.go b/markup/markup_config/config.go index be17c7b99..2dccbd6f8 100644 --- a/markup/markup_config/config.go +++ b/markup/markup_config/config.go @@ -111,5 +111,6 @@ var Default = Config{ Bibliography: bibliography.Default, Goldmark: goldmark_config.Default, + Pandoc: pandoc_config.Default, AsciidocExt: asciidocext_config.Default, } diff --git a/markup/pandoc/convert.go b/markup/pandoc/convert.go index a4caea57f..90a4fcc54 100644 --- a/markup/pandoc/convert.go +++ b/markup/pandoc/convert.go @@ -15,6 +15,7 @@ package pandoc import ( + "errors" "strings" "github.com/gohugoio/hugo/common/hexec" @@ -22,7 +23,6 @@ import ( "github.com/mitchellh/mapstructure" "github.com/gohugoio/hugo/identity" - "github.com/gohugoio/hugo/markup/bibliography" "github.com/gohugoio/hugo/markup/converter" "github.com/gohugoio/hugo/markup/internal" @@ -64,7 +64,7 @@ type pandocConverter struct { } func (c *pandocConverter) Convert(ctx converter.RenderContext) (converter.ResultRender, error) { - b, err := c.getPandocContent(ctx.Src, c.ctx) + b, err := c.getPandocContent(ctx.Src) if err != nil { return nil, err } @@ -76,17 +76,14 @@ 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) []byte { - logger := c.cfg.Logger +func (c *pandocConverter) getPandocContent(src []byte) ([]byte, error) { pandocPath, pandocFound := getPandocBinaryName() if !pandocFound { - logger.Println("pandoc not found in $PATH: Please install.\n", - " Leaving pandoc content unrendered.") - return src + return nil, errors.New("pandoc not found in $PATH: Please install.") } - var pandocConfig pandoc_config.Config = c.cfg.MarkupConfig.Pandoc - var bibConfig bibliography.Config = c.cfg.MarkupConfig.Bibliography + var pandocConfig pandoc_config.Config = c.cfg.MarkupConfig().Pandoc + var bibConfig bibliography.Config = c.cfg.MarkupConfig().Bibliography if pageParameters, ok := c.docCtx.Document.(paramer); ok { if bibParam, err := pageParameters.Param("bibliography"); err == nil { @@ -111,7 +108,7 @@ func (c *pandocConverter) getPandocContent(src []byte) []byte { arguments = append(arguments, "--resource-path", resourcePath) renderedContent, _ := internal.ExternallyRenderContent(c.cfg, c.docCtx, src, pandocPath, arguments) - return renderedContent + return renderedContent, nil } const pandocBinary = "pandoc" diff --git a/markup/pandoc/pandoc_config/pandoc.go b/markup/pandoc/pandoc_config/pandoc.go index 4c586b754..45d7cc6ad 100644 --- a/markup/pandoc/pandoc_config/pandoc.go +++ b/markup/pandoc/pandoc_config/pandoc.go @@ -69,6 +69,12 @@ type Config struct { ExtraArgs []string } +var Default = Config{ + InputFormat: "markdown", + UseLegacyHtml: false, + UseMathjax: true, +} + func (c *Config) getInputArg() string { var b strings.Builder b.WriteString("--from=")