mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-10 19:54:08 +02:00
Support typed bool, int and float in shortcode params
This means that you now can do: {{< vidur 9KvBeKu false true 32 3.14 >}} And the boolean and numeric values will be converted to `bool`, `int` and `float64`. If you want these to be strings, they must be quoted: {{< vidur 9KvBeKu "false" "true" "32" "3.14" >}} Fixes #6371
This commit is contained in:
@@ -112,7 +112,7 @@ func lexShortcodeParam(l *pageLexer, escapedQuoteStart bool) stateFunc {
|
||||
break
|
||||
}
|
||||
|
||||
if !isAlphaNumericOrHyphen(r) {
|
||||
if !isAlphaNumericOrHyphen(r) && r != '.' { // Floats have period
|
||||
l.backup()
|
||||
break
|
||||
}
|
||||
@@ -137,6 +137,12 @@ func lexShortcodeParam(l *pageLexer, escapedQuoteStart bool) stateFunc {
|
||||
|
||||
}
|
||||
|
||||
func lexShortcodeParamVal(l *pageLexer) stateFunc {
|
||||
l.consumeToSpace()
|
||||
l.emit(tScParamVal)
|
||||
return lexInsideShortcode
|
||||
}
|
||||
|
||||
func lexShortcodeQuotedParamVal(l *pageLexer, escapedQuotedValuesAllowed bool, typ ItemType) stateFunc {
|
||||
openQuoteFound := false
|
||||
escapedInnerQuoteFound := false
|
||||
@@ -176,9 +182,9 @@ Loop:
|
||||
}
|
||||
|
||||
if escapedInnerQuoteFound {
|
||||
l.ignoreEscapesAndEmit(typ)
|
||||
l.ignoreEscapesAndEmit(typ, true)
|
||||
} else {
|
||||
l.emit(typ)
|
||||
l.emitString(typ)
|
||||
}
|
||||
|
||||
r := l.next()
|
||||
@@ -273,8 +279,13 @@ func lexInsideShortcode(l *pageLexer) stateFunc {
|
||||
case isSpace(r), isEndOfLine(r):
|
||||
l.ignore()
|
||||
case r == '=':
|
||||
l.consumeSpace()
|
||||
l.ignore()
|
||||
return lexShortcodeQuotedParamVal(l, l.peek() != '\\', tScParamVal)
|
||||
peek := l.peek()
|
||||
if peek == '"' || peek == '\\' {
|
||||
return lexShortcodeQuotedParamVal(l, peek != '\\', tScParamVal)
|
||||
}
|
||||
return lexShortcodeParamVal
|
||||
case r == '/':
|
||||
if l.currShortcodeName == "" {
|
||||
return l.errorf("got closing shortcode, but none is open")
|
||||
|
Reference in New Issue
Block a user