You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

transform_heading.go 843B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package markdown
  4. import (
  5. "fmt"
  6. "code.gitea.io/gitea/modules/markup"
  7. "github.com/yuin/goldmark/ast"
  8. "github.com/yuin/goldmark/text"
  9. "github.com/yuin/goldmark/util"
  10. )
  11. func (g *ASTTransformer) transformHeading(ctx *markup.RenderContext, v *ast.Heading, reader text.Reader, tocList *[]markup.Header) {
  12. for _, attr := range v.Attributes() {
  13. if _, ok := attr.Value.([]byte); !ok {
  14. v.SetAttribute(attr.Name, []byte(fmt.Sprintf("%v", attr.Value)))
  15. }
  16. }
  17. txt := v.Text(reader.Source())
  18. header := markup.Header{
  19. Text: util.BytesToReadOnlyString(txt),
  20. Level: v.Level,
  21. }
  22. if id, found := v.AttributeString("id"); found {
  23. header.ID = util.BytesToReadOnlyString(id.([]byte))
  24. }
  25. *tocList = append(*tocList, header)
  26. g.applyElementDir(v)
  27. }