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:
Bjørn Erik Pedersen
2022-05-28 13:18:50 +02:00
parent 322d19a81f
commit d2cfaede5b
9 changed files with 208 additions and 4 deletions

View File

@@ -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