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

ast.go 3.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package markdown
  5. import (
  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. BaseBlock: ast.BaseBlock{},
  27. }
  28. }
  29. // IsDetails returns true if the given node implements the Details interface,
  30. // otherwise false.
  31. func IsDetails(node ast.Node) bool {
  32. _, ok := node.(*Details)
  33. return ok
  34. }
  35. // Summary is a block that contains the summary of details block
  36. type Summary struct {
  37. ast.BaseBlock
  38. }
  39. // Dump implements Node.Dump .
  40. func (n *Summary) Dump(source []byte, level int) {
  41. ast.DumpHelper(n, source, level, nil, nil)
  42. }
  43. // KindSummary is the NodeKind for Summary
  44. var KindSummary = ast.NewNodeKind("Summary")
  45. // Kind implements Node.Kind.
  46. func (n *Summary) Kind() ast.NodeKind {
  47. return KindSummary
  48. }
  49. // NewSummary returns a new Summary node.
  50. func NewSummary() *Summary {
  51. return &Summary{
  52. BaseBlock: ast.BaseBlock{},
  53. }
  54. }
  55. // IsSummary returns true if the given node implements the Summary interface,
  56. // otherwise false.
  57. func IsSummary(node ast.Node) bool {
  58. _, ok := node.(*Summary)
  59. return ok
  60. }
  61. // TaskCheckBoxListItem is a block that repressents a list item of a markdown block with a checkbox
  62. type TaskCheckBoxListItem struct {
  63. *ast.ListItem
  64. IsChecked bool
  65. }
  66. // KindTaskCheckBoxListItem is the NodeKind for TaskCheckBoxListItem
  67. var KindTaskCheckBoxListItem = ast.NewNodeKind("TaskCheckBoxListItem")
  68. // Dump implements Node.Dump .
  69. func (n *TaskCheckBoxListItem) Dump(source []byte, level int) {
  70. m := map[string]string{}
  71. m["IsChecked"] = strconv.FormatBool(n.IsChecked)
  72. ast.DumpHelper(n, source, level, m, nil)
  73. }
  74. // Kind implements Node.Kind.
  75. func (n *TaskCheckBoxListItem) Kind() ast.NodeKind {
  76. return KindTaskCheckBoxListItem
  77. }
  78. // NewTaskCheckBoxListItem returns a new TaskCheckBoxListItem node.
  79. func NewTaskCheckBoxListItem(listItem *ast.ListItem) *TaskCheckBoxListItem {
  80. return &TaskCheckBoxListItem{
  81. ListItem: listItem,
  82. }
  83. }
  84. // IsTaskCheckBoxListItem returns true if the given node implements the TaskCheckBoxListItem interface,
  85. // otherwise false.
  86. func IsTaskCheckBoxListItem(node ast.Node) bool {
  87. _, ok := node.(*TaskCheckBoxListItem)
  88. return ok
  89. }
  90. // Icon is an inline for a fomantic icon
  91. type Icon struct {
  92. ast.BaseInline
  93. Name []byte
  94. }
  95. // Dump implements Node.Dump .
  96. func (n *Icon) Dump(source []byte, level int) {
  97. m := map[string]string{}
  98. m["Name"] = string(n.Name)
  99. ast.DumpHelper(n, source, level, m, nil)
  100. }
  101. // KindIcon is the NodeKind for Icon
  102. var KindIcon = ast.NewNodeKind("Icon")
  103. // Kind implements Node.Kind.
  104. func (n *Icon) Kind() ast.NodeKind {
  105. return KindIcon
  106. }
  107. // NewIcon returns a new Paragraph node.
  108. func NewIcon(name string) *Icon {
  109. return &Icon{
  110. BaseInline: ast.BaseInline{},
  111. Name: []byte(name),
  112. }
  113. }
  114. // IsIcon returns true if the given node implements the Icon interface,
  115. // otherwise false.
  116. func IsIcon(node ast.Node) bool {
  117. _, ok := node.(*Icon)
  118. return ok
  119. }