summaryrefslogtreecommitdiffstats
path: root/helpers/pygments.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-05 10:20:06 +0700
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-17 17:15:26 +0100
commit93ca7c9e958e34469a337e4efcc7c75774ec50fd (patch)
tree5dfa296cfe74fd5ef8f0d41ea4078704f453aa04 /helpers/pygments.go
parente34af6ee30f70f5780a281e2fd8f4ed9b487ee61 (diff)
all: Refactor to nonglobal Viper, i18n etc.
This is a final rewrite that removes all the global state in Hugo, which also enables the use if `t.Parallel` in tests. Updates #2701 Fixes #3016
Diffstat (limited to 'helpers/pygments.go')
-rw-r--r--helpers/pygments.go26
1 files changed, 13 insertions, 13 deletions
diff --git a/helpers/pygments.go b/helpers/pygments.go
index 8e6d1a998..051612608 100644
--- a/helpers/pygments.go
+++ b/helpers/pygments.go
@@ -24,9 +24,9 @@ import (
"sort"
"strings"
+ "github.com/spf13/hugo/config"
"github.com/spf13/hugo/hugofs"
jww "github.com/spf13/jwalterweatherman"
- "github.com/spf13/viper"
)
const pygmentsBin = "pygmentize"
@@ -41,13 +41,13 @@ func HasPygments() bool {
}
// Highlight takes some code and returns highlighted code.
-func Highlight(code, lang, optsStr string) string {
+func Highlight(cfg config.Provider, code, lang, optsStr string) string {
if !HasPygments() {
jww.WARN.Println("Highlighting requires Pygments to be installed and in the path")
return code
}
- options, err := parsePygmentsOpts(optsStr)
+ options, err := parsePygmentsOpts(cfg, optsStr)
if err != nil {
jww.ERROR.Print(err.Error())
@@ -62,8 +62,8 @@ func Highlight(code, lang, optsStr string) string {
fs := hugofs.Os
- ignoreCache := viper.GetBool("ignoreCache")
- cacheDir := viper.GetString("cacheDir")
+ ignoreCache := cfg.GetBool("ignoreCache")
+ cacheDir := cfg.GetString("cacheDir")
var cachefile string
if !ignoreCache && cacheDir != "" {
@@ -195,19 +195,19 @@ func createOptionsString(options map[string]string) string {
return optionsStr
}
-func parseDefaultPygmentsOpts() (map[string]string, error) {
+func parseDefaultPygmentsOpts(cfg config.Provider) (map[string]string, error) {
options := make(map[string]string)
- err := parseOptions(options, viper.GetString("pygmentsOptions"))
+ err := parseOptions(options, cfg.GetString("pygmentsOptions"))
if err != nil {
return nil, err
}
- if viper.IsSet("pygmentsStyle") {
- options["style"] = viper.GetString("pygmentsStyle")
+ if cfg.IsSet("pygmentsStyle") {
+ options["style"] = cfg.GetString("pygmentsStyle")
}
- if viper.IsSet("pygmentsUseClasses") {
- if viper.GetBool("pygmentsUseClasses") {
+ if cfg.IsSet("pygmentsUseClasses") {
+ if cfg.GetBool("pygmentsUseClasses") {
options["noclasses"] = "false"
} else {
options["noclasses"] = "true"
@@ -222,8 +222,8 @@ func parseDefaultPygmentsOpts() (map[string]string, error) {
return options, nil
}
-func parsePygmentsOpts(in string) (string, error) {
- options, err := parseDefaultPygmentsOpts()
+func parsePygmentsOpts(cfg config.Provider, in string) (string, error) {
+ options, err := parseDefaultPygmentsOpts(cfg)
if err != nil {
return "", err
}