Skip to content

Commit 9e7645c

Browse files
committed
Support configuring a bibliography in markup config
1 parent 845aa4d commit 9e7645c

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

markup/bibliography/config.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2019 The Hugo Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package bibliography
15+
16+
type Config struct {
17+
// File containing bibliography. E.g. 'my-doc.bibtex'. By default assumed
18+
// to be in BibTex format.
19+
Source string
20+
21+
// Path to .csl file describing citation file.
22+
CitationStyle string
23+
}
24+
25+
var Default Config

markup/markup_config/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/gohugoio/hugo/config"
1818
"github.com/gohugoio/hugo/docshelper"
1919
"github.com/gohugoio/hugo/markup/asciidocext/asciidocext_config"
20+
"github.com/gohugoio/hugo/markup/bibliography"
2021
"github.com/gohugoio/hugo/markup/blackfriday/blackfriday_config"
2122
"github.com/gohugoio/hugo/markup/goldmark/goldmark_config"
2223
"github.com/gohugoio/hugo/markup/highlight"
@@ -34,6 +35,7 @@ type Config struct {
3435

3536
Highlight highlight.Config
3637
TableOfContents tableofcontents.Config
38+
Bibliography bibliography.Config
3739

3840
// Content renderers
3941
Goldmark goldmark_config.Config
@@ -92,6 +94,7 @@ var Default = Config{
9294

9395
TableOfContents: tableofcontents.DefaultConfig,
9496
Highlight: highlight.DefaultConfig,
97+
Bibliography: bibliography.Default,
9598

9699
Goldmark: goldmark_config.Default,
97100
BlackFriday: blackfriday_config.Default,

markup/pandoc/convert.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,19 @@ func (c *pandocConverter) getPandocContent(src []byte, ctx converter.DocumentCon
6262
return src
6363
}
6464

65-
return internal.ExternallyRenderContent(c.cfg, ctx, src, path, c.cfg.MarkupConfig.Pandoc.AsPandocArguments())
65+
arguments := c.cfg.MarkupConfig.Pandoc.AsPandocArguments()
66+
67+
bibliography := c.cfg.MarkupConfig.Bibliography
68+
69+
if bibliography.Source != "" {
70+
arguments = append(arguments, "--bibliography", bibliography.Source)
71+
}
72+
73+
if bibliography.CitationStyle != "" {
74+
arguments = append(arguments, "--csl", bibliography.CitationStyle)
75+
}
76+
77+
return internal.ExternallyRenderContent(c.cfg, ctx, src, path, arguments)
6678
}
6779

6880
func getPandocExecPath() string {

0 commit comments

Comments
 (0)