ref: 176ce5deab2b6a71789c14a401b8f9ed10399fde
parent: 967d001ebe40cfe90992d953880356a495216202
author: bep <[email protected]>
date: Fri Feb 27 06:57:23 EST 2015
Allow hyphens in shortcode name Fixes #929
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -33,6 +33,14 @@
CheckShortCodeMatch(t, "{{%/* movie 47238zzb */%}}", "{{% movie 47238zzb %}}", tem)
}
+// Issue #929
+func TestHyphenatedSC(t *testing.T) {
+ tem := tpl.New()
+ tem.AddInternalShortcode("hyphenated-video.html", `Playing Video {{ .Get 0 }}`)
+
+ CheckShortCodeMatch(t, "{{< hyphenated-video 47238zzb >}}", "Playing Video 47238zzb", tem)
+}
+
func TestPositionalParamSC(t *testing.T) {
tem := tpl.New()
tem.AddInternalShortcode("video.html", `Playing Video {{ .Get 0 }}`)
--- a/hugolib/shortcodeparser.go
+++ b/hugolib/shortcodeparser.go
@@ -382,7 +382,7 @@
break
}
- if !isValidParamRune(r) {
+ if !isAlphaNumericOrHyphen(r) {
l.backup()
break
}
@@ -477,7 +477,7 @@
Loop:
for {
switch r := l.next(); {
- case isAlphaNumeric(r):
+ case isAlphaNumericOrHyphen(r):
default:
l.backup()
word := l.input[l.start:l.pos]
@@ -541,7 +541,7 @@
if l.peek() == '"' {
return lexShortcodeParam(l, true)
}
- case l.elementStepNum > 0 && (isValidParamRune(r) || r == '"'): // positional params can have quotes
+ case l.elementStepNum > 0 && (isAlphaNumericOrHyphen(r) || r == '"'): // positional params can have quotes
l.backup()
return lexShortcodeParam(l, false)
case isAlphaNumeric(r):
@@ -584,7 +584,7 @@
return r == ' ' || r == '\t'
}
-func isValidParamRune(r rune) bool {
+func isAlphaNumericOrHyphen(r rune) bool {
// let unquoted YouTube ids as positional params slip through (they contain hyphens)
return isAlphaNumeric(r) || r == '-'
}