gitea源码

inline_node.go 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package math
  4. import (
  5. "github.com/yuin/goldmark/ast"
  6. "github.com/yuin/goldmark/util"
  7. )
  8. // Inline struct represents inline math e.g. $...$ or \(...\)
  9. type Inline struct {
  10. ast.BaseInline
  11. }
  12. // Inline implements Inline.Inline.
  13. func (n *Inline) Inline() {}
  14. // IsBlank returns if this inline node is empty
  15. func (n *Inline) IsBlank(source []byte) bool {
  16. for c := n.FirstChild(); c != nil; c = c.NextSibling() {
  17. text := c.(*ast.Text).Segment
  18. if !util.IsBlank(text.Value(source)) {
  19. return false
  20. }
  21. }
  22. return true
  23. }
  24. // Dump renders this inline math as debug
  25. func (n *Inline) Dump(source []byte, level int) {
  26. ast.DumpHelper(n, source, level, nil, nil)
  27. }
  28. // KindInline is the kind for math inline
  29. var KindInline = ast.NewNodeKind("MathInline")
  30. // Kind returns KindInline
  31. func (n *Inline) Kind() ast.NodeKind {
  32. return KindInline
  33. }
  34. // NewInline creates a new ast math inline node
  35. func NewInline() *Inline {
  36. return &Inline{
  37. BaseInline: ast.BaseInline{},
  38. }
  39. }