mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-28 14:40:43 +03: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:
parent
322d19a81f
commit
d2cfaede5b
9 changed files with 208 additions and 4 deletions
|
@ -120,6 +120,7 @@ func (l *pageLexer) next() rune {
|
|||
runeValue, runeWidth := utf8.DecodeRune(l.input[l.pos:])
|
||||
l.width = runeWidth
|
||||
l.pos += l.width
|
||||
|
||||
return runeValue
|
||||
}
|
||||
|
||||
|
@ -137,8 +138,34 @@ func (l *pageLexer) backup() {
|
|||
|
||||
// sends an item back to the client.
|
||||
func (l *pageLexer) emit(t ItemType) {
|
||||
defer func() {
|
||||
l.start = l.pos
|
||||
}()
|
||||
|
||||
if t == tText {
|
||||
// Identify any trailing whitespace/intendation.
|
||||
// We currently only care about the last one.
|
||||
for i := l.pos - 1; i >= l.start; i-- {
|
||||
b := l.input[i]
|
||||
if b != ' ' && b != '\t' && b != '\r' && b != '\n' {
|
||||
break
|
||||
}
|
||||
if i == l.start && b != '\n' {
|
||||
l.items = append(l.items, Item{tIndentation, l.start, l.input[l.start:l.pos], false})
|
||||
return
|
||||
} else if b == '\n' && i < l.pos-1 {
|
||||
l.items = append(l.items, Item{t, l.start, l.input[l.start : i+1], false})
|
||||
l.items = append(l.items, Item{tIndentation, i + 1, l.input[i+1 : l.pos], false})
|
||||
return
|
||||
} else if b == '\n' && i == l.pos-1 {
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue