code.gitea.io/gitea@v1.22.3/modules/markup/markdown/ast.go (about) 1 // Copyright 2020 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package markdown 5 6 import ( 7 "strconv" 8 9 "github.com/yuin/goldmark/ast" 10 ) 11 12 // Details is a block that contains Summary and details 13 type Details struct { 14 ast.BaseBlock 15 } 16 17 // Dump implements Node.Dump . 18 func (n *Details) Dump(source []byte, level int) { 19 ast.DumpHelper(n, source, level, nil, nil) 20 } 21 22 // KindDetails is the NodeKind for Details 23 var KindDetails = ast.NewNodeKind("Details") 24 25 // Kind implements Node.Kind. 26 func (n *Details) Kind() ast.NodeKind { 27 return KindDetails 28 } 29 30 // NewDetails returns a new Paragraph node. 31 func NewDetails() *Details { 32 return &Details{ 33 BaseBlock: ast.BaseBlock{}, 34 } 35 } 36 37 // IsDetails returns true if the given node implements the Details interface, 38 // otherwise false. 39 func IsDetails(node ast.Node) bool { 40 _, ok := node.(*Details) 41 return ok 42 } 43 44 // Summary is a block that contains the summary of details block 45 type Summary struct { 46 ast.BaseBlock 47 } 48 49 // Dump implements Node.Dump . 50 func (n *Summary) Dump(source []byte, level int) { 51 ast.DumpHelper(n, source, level, nil, nil) 52 } 53 54 // KindSummary is the NodeKind for Summary 55 var KindSummary = ast.NewNodeKind("Summary") 56 57 // Kind implements Node.Kind. 58 func (n *Summary) Kind() ast.NodeKind { 59 return KindSummary 60 } 61 62 // NewSummary returns a new Summary node. 63 func NewSummary() *Summary { 64 return &Summary{ 65 BaseBlock: ast.BaseBlock{}, 66 } 67 } 68 69 // IsSummary returns true if the given node implements the Summary interface, 70 // otherwise false. 71 func IsSummary(node ast.Node) bool { 72 _, ok := node.(*Summary) 73 return ok 74 } 75 76 // TaskCheckBoxListItem is a block that represents a list item of a markdown block with a checkbox 77 type TaskCheckBoxListItem struct { 78 *ast.ListItem 79 IsChecked bool 80 SourcePosition int 81 } 82 83 // KindTaskCheckBoxListItem is the NodeKind for TaskCheckBoxListItem 84 var KindTaskCheckBoxListItem = ast.NewNodeKind("TaskCheckBoxListItem") 85 86 // Dump implements Node.Dump . 87 func (n *TaskCheckBoxListItem) Dump(source []byte, level int) { 88 m := map[string]string{} 89 m["IsChecked"] = strconv.FormatBool(n.IsChecked) 90 m["SourcePosition"] = strconv.FormatInt(int64(n.SourcePosition), 10) 91 ast.DumpHelper(n, source, level, m, nil) 92 } 93 94 // Kind implements Node.Kind. 95 func (n *TaskCheckBoxListItem) Kind() ast.NodeKind { 96 return KindTaskCheckBoxListItem 97 } 98 99 // NewTaskCheckBoxListItem returns a new TaskCheckBoxListItem node. 100 func NewTaskCheckBoxListItem(listItem *ast.ListItem) *TaskCheckBoxListItem { 101 return &TaskCheckBoxListItem{ 102 ListItem: listItem, 103 } 104 } 105 106 // IsTaskCheckBoxListItem returns true if the given node implements the TaskCheckBoxListItem interface, 107 // otherwise false. 108 func IsTaskCheckBoxListItem(node ast.Node) bool { 109 _, ok := node.(*TaskCheckBoxListItem) 110 return ok 111 } 112 113 // Icon is an inline for a fomantic icon 114 type Icon struct { 115 ast.BaseInline 116 Name []byte 117 } 118 119 // Dump implements Node.Dump . 120 func (n *Icon) Dump(source []byte, level int) { 121 m := map[string]string{} 122 m["Name"] = string(n.Name) 123 ast.DumpHelper(n, source, level, m, nil) 124 } 125 126 // KindIcon is the NodeKind for Icon 127 var KindIcon = ast.NewNodeKind("Icon") 128 129 // Kind implements Node.Kind. 130 func (n *Icon) Kind() ast.NodeKind { 131 return KindIcon 132 } 133 134 // NewIcon returns a new Paragraph node. 135 func NewIcon(name string) *Icon { 136 return &Icon{ 137 BaseInline: ast.BaseInline{}, 138 Name: []byte(name), 139 } 140 } 141 142 // IsIcon returns true if the given node implements the Icon interface, 143 // otherwise false. 144 func IsIcon(node ast.Node) bool { 145 _, ok := node.(*Icon) 146 return ok 147 } 148 149 // ColorPreview is an inline for a color preview 150 type ColorPreview struct { 151 ast.BaseInline 152 Color []byte 153 } 154 155 // Dump implements Node.Dump. 156 func (n *ColorPreview) Dump(source []byte, level int) { 157 m := map[string]string{} 158 m["Color"] = string(n.Color) 159 ast.DumpHelper(n, source, level, m, nil) 160 } 161 162 // KindColorPreview is the NodeKind for ColorPreview 163 var KindColorPreview = ast.NewNodeKind("ColorPreview") 164 165 // Kind implements Node.Kind. 166 func (n *ColorPreview) Kind() ast.NodeKind { 167 return KindColorPreview 168 } 169 170 // NewColorPreview returns a new Span node. 171 func NewColorPreview(color []byte) *ColorPreview { 172 return &ColorPreview{ 173 BaseInline: ast.BaseInline{}, 174 Color: color, 175 } 176 } 177 178 // Attention is an inline for an attention 179 type Attention struct { 180 ast.BaseInline 181 AttentionType string 182 } 183 184 // Dump implements Node.Dump. 185 func (n *Attention) Dump(source []byte, level int) { 186 m := map[string]string{} 187 m["AttentionType"] = n.AttentionType 188 ast.DumpHelper(n, source, level, m, nil) 189 } 190 191 // KindAttention is the NodeKind for Attention 192 var KindAttention = ast.NewNodeKind("Attention") 193 194 // Kind implements Node.Kind. 195 func (n *Attention) Kind() ast.NodeKind { 196 return KindAttention 197 } 198 199 // NewAttention returns a new Attention node. 200 func NewAttention(attentionType string) *Attention { 201 return &Attention{ 202 BaseInline: ast.BaseInline{}, 203 AttentionType: attentionType, 204 } 205 }