mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-10 19:54:08 +02:00
Improve shortcode indentation handling
* Record the leading whitespace (tabs, spaces) before the shortcode when parsing the page. * Apply that indentation to the rendered result of shortcodes without inner content (where the user will apply indentation). Fixes #9946
This commit is contained in:
@@ -18,6 +18,8 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"github.com/yuin/goldmark/util"
|
||||
)
|
||||
|
||||
type Item struct {
|
||||
@@ -64,7 +66,11 @@ func (i Item) ValTyped() any {
|
||||
}
|
||||
|
||||
func (i Item) IsText() bool {
|
||||
return i.Type == tText
|
||||
return i.Type == tText || i.Type == tIndentation
|
||||
}
|
||||
|
||||
func (i Item) IsIndentation() bool {
|
||||
return i.Type == tIndentation
|
||||
}
|
||||
|
||||
func (i Item) IsNonWhitespace() bool {
|
||||
@@ -125,6 +131,8 @@ func (i Item) String() string {
|
||||
return "EOF"
|
||||
case i.Type == tError:
|
||||
return string(i.Val)
|
||||
case i.Type == tIndentation:
|
||||
return fmt.Sprintf("%s:[%s]", i.Type, util.VisualizeSpaces(i.Val))
|
||||
case i.Type > tKeywordMarker:
|
||||
return fmt.Sprintf("<%s>", i.Val)
|
||||
case len(i.Val) > 50:
|
||||
@@ -159,6 +167,8 @@ const (
|
||||
tScParam
|
||||
tScParamVal
|
||||
|
||||
tIndentation
|
||||
|
||||
tText // plain text
|
||||
|
||||
// preserved for later - keywords come after this
|
||||
|
Reference in New Issue
Block a user