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:
Bjørn Erik Pedersen
2019-09-29 14:51:51 +02:00
parent e073f4efb1
commit 329e88db1f
12 changed files with 202 additions and 53 deletions

View File

@@ -142,7 +142,13 @@ func (l *pageLexer) backup() {
// sends an item back to the client.
func (l *pageLexer) emit(t ItemType) {
l.items = append(l.items, Item{t, l.start, l.input[l.start:l.pos]})
l.items = append(l.items, Item{t, l.start, l.input[l.start:l.pos], false})
l.start = l.pos
}
// sends a string item back to the client.
func (l *pageLexer) emitString(t ItemType) {
l.items = append(l.items, Item{t, l.start, l.input[l.start:l.pos], true})
l.start = l.pos
}
@@ -151,14 +157,14 @@ func (l *pageLexer) isEOF() bool {
}
// special case, do not send '\\' back to client
func (l *pageLexer) ignoreEscapesAndEmit(t ItemType) {
func (l *pageLexer) ignoreEscapesAndEmit(t ItemType, isString bool) {
val := bytes.Map(func(r rune) rune {
if r == '\\' {
return -1
}
return r
}, l.input[l.start:l.pos])
l.items = append(l.items, Item{t, l.start, val})
l.items = append(l.items, Item{t, l.start, val, isString})
l.start = l.pos
}
@@ -176,7 +182,7 @@ var lf = []byte("\n")
// nil terminates the parser
func (l *pageLexer) errorf(format string, args ...interface{}) stateFunc {
l.items = append(l.items, Item{tError, l.start, []byte(fmt.Sprintf(format, args...))})
l.items = append(l.items, Item{tError, l.start, []byte(fmt.Sprintf(format, args...)), true})
return nil
}
@@ -201,6 +207,16 @@ func (l *pageLexer) consumeToNextLine() {
}
}
func (l *pageLexer) consumeToSpace() {
for {
r := l.next()
if r == eof || unicode.IsSpace(r) {
l.backup()
return
}
}
}
func (l *pageLexer) consumeSpace() {
for {
r := l.next()