Skip to content

Commit

Permalink
Add configuration options for pandoc
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
asankah committed Sep 13, 2023
1 parent c9e6790 commit b5c5a8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions markup/markup_config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ var Default = Config{
Bibliography: bibliography.Default,

Goldmark: goldmark_config.Default,
Pandoc: pandoc_config.Default,
AsciidocExt: asciidocext_config.Default,
}
17 changes: 7 additions & 10 deletions markup/pandoc/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
package pandoc

import (
"errors"
"strings"

"github.com/gohugoio/hugo/common/hexec"
"github.com/gohugoio/hugo/htesting"
"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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand All @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions markup/pandoc/pandoc_config/pandoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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=")
Expand Down

0 comments on commit b5c5a8b

Please sign in to comment.