Make .RenderString render shortcodes

Fixes #6703
This commit is contained in:
Bjørn Erik Pedersen
2022-05-29 16:41:57 +02:00
parent d2cfaede5b
commit 9e904d756b
10 changed files with 315 additions and 111 deletions

View File

@@ -64,11 +64,12 @@ func Puts(s string) string {
// VisitLinesAfter calls the given function for each line, including newlines, in the given string.
func VisitLinesAfter(s string, fn func(line string)) {
high := strings.Index(s, "\n")
high := strings.IndexRune(s, '\n')
for high != -1 {
fn(s[:high+1])
s = s[high+1:]
high = strings.Index(s, "\n")
high = strings.IndexRune(s, '\n')
}
if s != "" {

View File

@@ -59,3 +59,18 @@ line 3`
c.Assert(collected, qt.DeepEquals, []string{"line 1\n", "line 2\n", "\n", "line 3"})
}
func BenchmarkVisitLinesAfter(b *testing.B) {
const lines = `line 1
line 2
line 3`
for i := 0; i < b.N; i++ {
VisitLinesAfter(lines, func(s string) {
})
}
}