gitea源码

ast.go 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package markdown
  4. import (
  5. "html/template"
  6. "strconv"
  7. "github.com/yuin/goldmark/ast"
  8. )
  9. // Details is a block that contains Summary and details
  10. type Details struct {
  11. ast.BaseBlock
  12. }
  13. // Dump implements Node.Dump .
  14. func (n *Details) Dump(source []byte, level int) {
  15. ast.DumpHelper(n, source, level, nil, nil)
  16. }
  17. // KindDetails is the NodeKind for Details
  18. var KindDetails = ast.NewNodeKind("Details")
  19. // Kind implements Node.Kind.
  20. func (n *Details) Kind() ast.NodeKind {
  21. return KindDetails
  22. }
  23. // NewDetails returns a new Paragraph node.
  24. func NewDetails() *Details {
  25. return &Details{}
  26. }
  27. // Summary is a block that contains the summary of details block
  28. type Summary struct {
  29. ast.BaseBlock
  30. }
  31. // Dump implements Node.Dump .
  32. func (n *Summary) Dump(source []byte, level int) {
  33. ast.DumpHelper(n, source, level, nil, nil)
  34. }
  35. // KindSummary is the NodeKind for Summary
  36. var KindSummary = ast.NewNodeKind("Summary")
  37. // Kind implements Node.Kind.
  38. func (n *Summary) Kind() ast.NodeKind {
  39. return KindSummary
  40. }
  41. // NewSummary returns a new Summary node.
  42. func NewSummary() *Summary {
  43. return &Summary{}
  44. }
  45. // TaskCheckBoxListItem is a block that represents a list item of a markdown block with a checkbox
  46. type TaskCheckBoxListItem struct {
  47. *ast.ListItem
  48. IsChecked bool
  49. SourcePosition int
  50. }
  51. // KindTaskCheckBoxListItem is the NodeKind for TaskCheckBoxListItem
  52. var KindTaskCheckBoxListItem = ast.NewNodeKind("TaskCheckBoxListItem")
  53. // Dump implements Node.Dump .
  54. func (n *TaskCheckBoxListItem) Dump(source []byte, level int) {
  55. m := map[string]string{}
  56. m["IsChecked"] = strconv.FormatBool(n.IsChecked)
  57. m["SourcePosition"] = strconv.FormatInt(int64(n.SourcePosition), 10)
  58. ast.DumpHelper(n, source, level, m, nil)
  59. }
  60. // Kind implements Node.Kind.
  61. func (n *TaskCheckBoxListItem) Kind() ast.NodeKind {
  62. return KindTaskCheckBoxListItem
  63. }
  64. // NewTaskCheckBoxListItem returns a new TaskCheckBoxListItem node.
  65. func NewTaskCheckBoxListItem(listItem *ast.ListItem) *TaskCheckBoxListItem {
  66. return &TaskCheckBoxListItem{
  67. ListItem: listItem,
  68. }
  69. }
  70. // Icon is an inline for a Fomantic UI icon
  71. type Icon struct {
  72. ast.BaseInline
  73. Name []byte
  74. }
  75. // ColorPreview is an inline for a color preview
  76. type ColorPreview struct {
  77. ast.BaseInline
  78. Color []byte
  79. }
  80. // Dump implements Node.Dump.
  81. func (n *ColorPreview) Dump(source []byte, level int) {
  82. m := map[string]string{}
  83. m["Color"] = string(n.Color)
  84. ast.DumpHelper(n, source, level, m, nil)
  85. }
  86. // KindColorPreview is the NodeKind for ColorPreview
  87. var KindColorPreview = ast.NewNodeKind("ColorPreview")
  88. // Kind implements Node.Kind.
  89. func (n *ColorPreview) Kind() ast.NodeKind {
  90. return KindColorPreview
  91. }
  92. // NewColorPreview returns a new Span node.
  93. func NewColorPreview(color []byte) *ColorPreview {
  94. return &ColorPreview{
  95. BaseInline: ast.BaseInline{},
  96. Color: color,
  97. }
  98. }
  99. // Attention is an inline for an attention
  100. type Attention struct {
  101. ast.BaseInline
  102. AttentionType string
  103. }
  104. // Dump implements Node.Dump.
  105. func (n *Attention) Dump(source []byte, level int) {
  106. m := map[string]string{}
  107. m["AttentionType"] = n.AttentionType
  108. ast.DumpHelper(n, source, level, m, nil)
  109. }
  110. // KindAttention is the NodeKind for Attention
  111. var KindAttention = ast.NewNodeKind("Attention")
  112. // Kind implements Node.Kind.
  113. func (n *Attention) Kind() ast.NodeKind {
  114. return KindAttention
  115. }
  116. // NewAttention returns a new Attention node.
  117. func NewAttention(attentionType string) *Attention {
  118. return &Attention{
  119. BaseInline: ast.BaseInline{},
  120. AttentionType: attentionType,
  121. }
  122. }
  123. var KindRawHTML = ast.NewNodeKind("RawHTML")
  124. type RawHTML struct {
  125. ast.BaseBlock
  126. rawHTML template.HTML
  127. }
  128. func (n *RawHTML) Dump(source []byte, level int) {
  129. m := map[string]string{}
  130. m["RawHTML"] = string(n.rawHTML)
  131. ast.DumpHelper(n, source, level, m, nil)
  132. }
  133. func (n *RawHTML) Kind() ast.NodeKind {
  134. return KindRawHTML
  135. }
  136. func NewRawHTML(rawHTML template.HTML) *RawHTML {
  137. return &RawHTML{rawHTML: rawHTML}
  138. }