Add pygmentsstyle and pygmentsuseclasses options
authorLK4D4 <lk4d4math@gmail.com>
Wed, 7 May 2014 16:38:14 +0000 (20:38 +0400)
committerspf13 <steve.francia@gmail.com>
Sat, 10 May 2014 03:20:11 +0000 (23:20 -0400)
Fixes #204

Conflicts:
commands/hugo.go

commands/hugo.go
docs/content/extras/highlighting.md
helpers/pygments.go

index 8d18b6252dfda751519c922293bd2490f89b1bb0..369403ddbe46ebb38cd00272a6fe41150b6e3ae3 100644 (file)
@@ -110,6 +110,8 @@ func InitializeConfig() {
        viper.SetDefault("Indexes", map[string]string{"tag": "tags", "category": "categories"})
        viper.SetDefault("Permalinks", make(hugolib.PermalinkOverrides, 0))
        viper.SetDefault("Sitemap", hugolib.Sitemap{Priority: -1})
+       viper.SetDefault("PygmentsStyle", "monokai")
+       viper.SetDefault("PygmentsUseClasses", false)
 
        if hugoCmdV.PersistentFlags().Lookup("build-drafts").Changed {
                viper.Set("BuildDrafts", Draft)
@@ -134,7 +136,6 @@ func InitializeConfig() {
        if hugoCmdV.PersistentFlags().Lookup("logfile").Changed {
                viper.Set("LogFile", LogFile)
        }
-
        if BaseUrl != "" {
                if !strings.HasSuffix(BaseUrl, "/") {
                        BaseUrl = BaseUrl + "/"
index 534b973c4b4aff539f0cb22ac4c0210487632b3a..0f82202bcb3fffa26a11d3b242c3fa0fb1e37d09 100644 (file)
@@ -27,13 +27,13 @@ silently simply pass the content along unhighlighted.
  * **Warning** pygments is relatively slow and our integration isn't
 as optimized as it could be. Expect much longer build times when using server side highlighting.
  * Languages available depends on your pygments installation.
- * While pygments supports a few different output formats and options we currently
-only support output=html, style=monokai, noclasses=true, and encoding=utf-8.
  * Styles are inline in order to be supported in syndicated content when references
 to style sheets are not carried over.
  * We have sought to have the simplest interface possible, which consequently
 limits configuration. An ambitious user is encouraged to extend the current
 functionality to offer more customization.
+* You can change appearance with config options `pygmentsstyle`(default
+`"monokai"`) and `pygmentsuseclasses`(defaut `false`).
 
 ### Usage
 Highlight takes exactly one required parameter of language and requires a
index 46eb879e58adb7b3d20c085ed849e2dbf30fae0f..2ff500da3d88cfe0473dd6de567e3a8ceb1d9d6f 100644 (file)
@@ -15,10 +15,12 @@ package helpers
 
 import (
        "bytes"
+       "fmt"
        "os/exec"
        "strings"
 
        jww "github.com/spf13/jwalterweatherman"
+       "github.com/spf13/viper"
 )
 
 func Highlight(code string, lexer string) string {
@@ -32,8 +34,15 @@ func Highlight(code string, lexer string) string {
 
        var out bytes.Buffer
        var stderr bytes.Buffer
+       style := viper.GetString("PygmentsStyle")
 
-       cmd := exec.Command(pygmentsBin, "-l"+lexer, "-fhtml", "-O style=monokai,noclasses=true,encoding=utf-8")
+       noclasses := "true"
+       if viper.GetBool("PygmentsUseClasses") {
+               noclasses = "false"
+       }
+
+       cmd := exec.Command(pygmentsBin, "-l"+lexer, "-fhtml", "-O",
+               fmt.Sprintf("style=%s,noclasses=%s,encoding=utf8", style, noclasses))
        cmd.Stdin = strings.NewReader(code)
        cmd.Stdout = &out
        cmd.Stderr = &stderr