Skip to content

Commit 90b8547

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
1 parent 19ef27b commit 90b8547

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1
367367
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
368368
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
369369
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
370+
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
370371
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
371372
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
372373
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=

markup/markup_config/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/gohugoio/hugo/markup/asciidocext/asciidocext_config"
2020
"github.com/gohugoio/hugo/markup/blackfriday/blackfriday_config"
2121
"github.com/gohugoio/hugo/markup/goldmark/goldmark_config"
22+
"github.com/gohugoio/hugo/markup/pandoc/pandoc_config"
2223
"github.com/gohugoio/hugo/markup/highlight"
2324
"github.com/gohugoio/hugo/markup/tableofcontents"
2425
"github.com/gohugoio/hugo/parser"
@@ -37,6 +38,7 @@ type Config struct {
3738
// Content renderers
3839
Goldmark goldmark_config.Config
3940
BlackFriday blackfriday_config.Config
41+
Pandoc pandoc_config.Config
4042

4143
AsciidocExt asciidocext_config.Config
4244
}

markup/pandoc/convert.go

+26-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package pandoc
1616

1717
import (
18+
"strings"
19+
"fmt"
1820
"os/exec"
1921

2022
"github.com/gohugoio/hugo/identity"
@@ -36,7 +38,6 @@ func (p provider) New(cfg converter.ProviderConfig) (converter.Provider, error)
3638
cfg: cfg,
3739
}, nil
3840
}), nil
39-
4041
}
4142

4243
type pandocConverter struct {
@@ -57,11 +58,34 @@ func (c *pandocConverter) getPandocContent(src []byte, ctx converter.DocumentCon
5758
logger := c.cfg.Logger
5859
path := getPandocExecPath()
5960
if path == "" {
60-
logger.ERROR.Println("pandoc not found in $PATH: Please install.\n",
61+
logger.ERROR.Println(
62+
"pandoc not found in $PATH: Please install.\n",
6163
" Leaving pandoc content unrendered.")
6264
return src
6365
}
66+
6467
args := []string{"--mathjax"}
68+
69+
if len(c.cfg.MarkupConfig.Pandoc.Filters) > 0 {
70+
for _, filter := range c.cfg.MarkupConfig.Pandoc.Filters {
71+
args = append(args, fmt.Sprintf("--filter=%s", filter))
72+
}
73+
}
74+
75+
if len(c.cfg.MarkupConfig.Pandoc.Extensions) > 0 {
76+
var b strings.Builder
77+
b.WriteString("--from=markdown")
78+
for _, extension := range c.cfg.MarkupConfig.Pandoc.Extensions {
79+
b.WriteString("+")
80+
b.WriteString(extension)
81+
}
82+
args = append(args, b.String())
83+
}
84+
85+
if len(c.cfg.MarkupConfig.Pandoc.ExtraArgs) > 0 {
86+
args = append(args, c.cfg.MarkupConfig.Pandoc.ExtraArgs...)
87+
}
88+
6589
return internal.ExternallyRenderContent(c.cfg, ctx, src, path, args)
6690
}
6791

markup/pandoc/pandoc_config/pandoc.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package pandoc_config
2+
3+
// Config contains configuration settings for Pandoc.
4+
type Config struct {
5+
// Input format. Use the 'Extensions' field to specify extensions thereof.
6+
// Only specify the bare format here. Defaults to 'markdown' if empty. Invoke
7+
// "pandoc --list-input-formats" to see the list of supported input formats
8+
// including various Markdown dialects.
9+
InputFormat string
10+
11+
// If true, the output format is HTML (i.e. "--to=html"). Otherwise the output
12+
// format is HTML5 (i.e. "--to=html5").
13+
UseLegacyHtml bool
14+
15+
// Equivalent to specifying "--mathjax". For compatibility, this option is
16+
// always true if none of the other math options are used.
17+
// See https://pandoc.org/MANUAL.html#math-rendering-in-html
18+
UseMathjax bool
19+
20+
// Equivalent to specifying "--mathml".
21+
// See https://pandoc.org/MANUAL.html#math-rendering-in-html
22+
UseMathml bool
23+
24+
// Equivalent to specifying "--webtex".
25+
// See https://pandoc.org/MANUAL.html#math-rendering-in-html. Uses the default
26+
// Webtex rendering URL.
27+
UseWebtex bool
28+
29+
// Equivalent to specifying "--katex".
30+
// See https://pandoc.org/MANUAL.html#math-rendering-in-html
31+
UseKatex bool
32+
33+
// List of filters to use. These translate to '--filter=' arguments to the
34+
// pandoc invocation. The order of elements in `Filters` is preserved when
35+
// constructing the `pandoc` commandline.
36+
Filters []string
37+
38+
// List of Pandoc Markdown extensions to use. No need to include default
39+
// extensions. Specifying ["foo", "bar"] is equivalent to specifying
40+
// --from=markdown+foo+bar on the pandoc commandline.
41+
Extensions []string
42+
43+
// Random extra arguments.
44+
ExtraArgs []string
45+
}

0 commit comments

Comments
 (0)