2024-11-02 13:35:24 +01:00
|
|
|
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"github.com/yuin/goldmark/ast"
|
2025-07-06 22:00:09 +02:00
|
|
|
"github.com/yuin/goldmark/parser"
|
2024-11-02 13:35:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func textOfChildren(n ast.Node, src []byte, b *bytes.Buffer) {
|
|
|
|
for c := n.FirstChild(); c != nil; c = c.NextSibling() {
|
|
|
|
if t, ok := c.(*ast.Text); ok {
|
|
|
|
b.Write(t.Value(src))
|
|
|
|
} else {
|
|
|
|
textOfChildren(c, src, b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Text(n ast.Node, src []byte) []byte {
|
|
|
|
var b bytes.Buffer
|
|
|
|
textOfChildren(n, src, &b)
|
|
|
|
return b.Bytes()
|
|
|
|
}
|
2025-07-06 22:00:09 +02:00
|
|
|
|
|
|
|
var (
|
|
|
|
RenderContextKey = parser.NewContextKey()
|
|
|
|
RenderConfigKey = parser.NewContextKey()
|
|
|
|
)
|