Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbep <bjorn.erik.pedersen@gmail.com>2014-10-27 23:48:30 +0300
committerspf13 <steve.francia@gmail.com>2014-11-18 02:32:06 +0300
commit55fcd2f30f4358a800932aa60160935c0c22f96d (patch)
tree8bd9aa1cf0df4fb186d1e0ec07e21fdda4591b89 /helpers
parentc8904756f02948c6f7bb900b05cd0aa6b259088e (diff)
Shortcode rewrite, take 2
This commit contains a restructuring and partial rewrite of the shortcode handling. Prior to this commit rendering of the page content was mingled with handling of the shortcodes. This led to several oddities. The new flow is: 1. Shortcodes are extracted from page and replaced with placeholders. 2. Shortcodes are processed and rendered 3. Page is processed 4. The placeholders are replaced with the rendered shortcodes The handling of summaries is also made simpler by this. This commit also introduces some other chenges: 1. distinction between shortcodes that need further processing and those who do not: * `{{< >}}`: Typically raw HTML. Will not be processed. * `{{% %}}`: Will be processed by the page's markup engine (Markdown or (infuture) Asciidoctor) The above also involves a new shortcode-parser, with lexical scanning inspired by Rob Pike's talk called "Lexical Scanning in Go", which should be easier to understand, give better error messages and perform better. 2. If you want to exclude a shortcode from being processed (for documentation etc.), the inner part of the shorcode must be commented out, i.e. `{{%/* movie 47238zzb */%}}`. See the updated shortcode section in the documentation for further examples. The new parser supports nested shortcodes. This isn't new, but has two related design choices worth mentioning: * The shortcodes will be rendered individually, so If both `{{< >}}` and `{{% %}}` are used in the nested hierarchy, one will be passed through the page's markdown processor, the other not. * To avoid potential costly overhead of always looking far ahead for a possible closing tag, this implementation looks at the template itself, and is branded as a container with inner content if it contains a reference to `.Inner` Fixes #565 Fixes #480 Fixes #461 And probably some others.
Diffstat (limited to 'helpers')
-rw-r--r--helpers/pygments.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/helpers/pygments.go b/helpers/pygments.go
index 2ff500da3..bb7790533 100644
--- a/helpers/pygments.go
+++ b/helpers/pygments.go
@@ -1,4 +1,4 @@
-// Copyright © 2013 Steve Francia <spf@spf13.com>.
+// Copyright © 2013-14 Steve Francia <spf@spf13.com>.
//
// Licensed under the Simple Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -23,11 +23,18 @@ import (
"github.com/spf13/viper"
)
-func Highlight(code string, lexer string) string {
- var pygmentsBin = "pygmentize"
+const pygmentsBin = "pygmentize"
+func HasPygments() bool {
if _, err := exec.LookPath(pygmentsBin); err != nil {
+ return false
+ }
+ return true
+}
+
+func Highlight(code string, lexer string) string {
+ if !HasPygments() {
jww.WARN.Println("Highlighting requires Pygments to be installed and in the path")
return code
}