mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-22 20:52:27 +00:00
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.
This commit is contained in:
parent
c9e679075f
commit
b5c5a8bd76
3 changed files with 14 additions and 10 deletions
|
@ -111,5 +111,6 @@ var Default = Config{
|
||||||
Bibliography: bibliography.Default,
|
Bibliography: bibliography.Default,
|
||||||
|
|
||||||
Goldmark: goldmark_config.Default,
|
Goldmark: goldmark_config.Default,
|
||||||
|
Pandoc: pandoc_config.Default,
|
||||||
AsciidocExt: asciidocext_config.Default,
|
AsciidocExt: asciidocext_config.Default,
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package pandoc
|
package pandoc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/common/hexec"
|
"github.com/gohugoio/hugo/common/hexec"
|
||||||
|
@ -22,7 +23,6 @@ import (
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/identity"
|
"github.com/gohugoio/hugo/identity"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/markup/bibliography"
|
"github.com/gohugoio/hugo/markup/bibliography"
|
||||||
"github.com/gohugoio/hugo/markup/converter"
|
"github.com/gohugoio/hugo/markup/converter"
|
||||||
"github.com/gohugoio/hugo/markup/internal"
|
"github.com/gohugoio/hugo/markup/internal"
|
||||||
|
@ -64,7 +64,7 @@ type pandocConverter struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *pandocConverter) Convert(ctx converter.RenderContext) (converter.ResultRender, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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.
|
// getPandocContent calls pandoc as an external helper to convert pandoc markdown to HTML.
|
||||||
func (c *pandocConverter) getPandocContent(src []byte) []byte {
|
func (c *pandocConverter) getPandocContent(src []byte) ([]byte, error) {
|
||||||
logger := c.cfg.Logger
|
|
||||||
pandocPath, pandocFound := getPandocBinaryName()
|
pandocPath, pandocFound := getPandocBinaryName()
|
||||||
if !pandocFound {
|
if !pandocFound {
|
||||||
logger.Println("pandoc not found in $PATH: Please install.\n",
|
return nil, errors.New("pandoc not found in $PATH: Please install.")
|
||||||
" Leaving pandoc content unrendered.")
|
|
||||||
return src
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var pandocConfig pandoc_config.Config = c.cfg.MarkupConfig.Pandoc
|
var pandocConfig pandoc_config.Config = c.cfg.MarkupConfig().Pandoc
|
||||||
var bibConfig bibliography.Config = c.cfg.MarkupConfig.Bibliography
|
var bibConfig bibliography.Config = c.cfg.MarkupConfig().Bibliography
|
||||||
|
|
||||||
if pageParameters, ok := c.docCtx.Document.(paramer); ok {
|
if pageParameters, ok := c.docCtx.Document.(paramer); ok {
|
||||||
if bibParam, err := pageParameters.Param("bibliography"); err == nil {
|
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)
|
arguments = append(arguments, "--resource-path", resourcePath)
|
||||||
|
|
||||||
renderedContent, _ := internal.ExternallyRenderContent(c.cfg, c.docCtx, src, pandocPath, arguments)
|
renderedContent, _ := internal.ExternallyRenderContent(c.cfg, c.docCtx, src, pandocPath, arguments)
|
||||||
return renderedContent
|
return renderedContent, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const pandocBinary = "pandoc"
|
const pandocBinary = "pandoc"
|
||||||
|
|
|
@ -69,6 +69,12 @@ type Config struct {
|
||||||
ExtraArgs []string
|
ExtraArgs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Default = Config{
|
||||||
|
InputFormat: "markdown",
|
||||||
|
UseLegacyHtml: false,
|
||||||
|
UseMathjax: true,
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Config) getInputArg() string {
|
func (c *Config) getInputArg() string {
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
b.WriteString("--from=")
|
b.WriteString("--from=")
|
||||||
|
|
Loading…
Reference in a new issue