code.gitea.io/gitea@v1.19.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 } 81 82 // KindTaskCheckBoxListItem is the NodeKind for TaskCheckBoxListItem 83 var KindTaskCheckBoxListItem = ast.NewNodeKind("TaskCheckBoxListItem") 84 85 // Dump implements Node.Dump . 86 func (n *TaskCheckBoxListItem) Dump(source []byte, level int) { 87 m := map[string]string{} 88 m["IsChecked"] = strconv.FormatBool(n.IsChecked) 89 ast.DumpHelper(n, source, level, m, nil) 90 } 91 92 // Kind implements Node.Kind. 93 func (n *TaskCheckBoxListItem) Kind() ast.NodeKind { 94 return KindTaskCheckBoxListItem 95 } 96 97 // NewTaskCheckBoxListItem returns a new TaskCheckBoxListItem node. 98 func NewTaskCheckBoxListItem(listItem *ast.ListItem) *TaskCheckBoxListItem { 99 return &TaskCheckBoxListItem{ 100 ListItem: listItem, 101 } 102 } 103 104 // IsTaskCheckBoxListItem returns true if the given node implements the TaskCheckBoxListItem interface, 105 // otherwise false. 106 func IsTaskCheckBoxListItem(node ast.Node) bool { 107 _, ok := node.(*TaskCheckBoxListItem) 108 return ok 109 } 110 111 // Icon is an inline for a fomantic icon 112 type Icon struct { 113 ast.BaseInline 114 Name []byte 115 } 116 117 // Dump implements Node.Dump . 118 func (n *Icon) Dump(source []byte, level int) { 119 m := map[string]string{} 120 m["Name"] = string(n.Name) 121 ast.DumpHelper(n, source, level, m, nil) 122 } 123 124 // KindIcon is the NodeKind for Icon 125 var KindIcon = ast.NewNodeKind("Icon") 126 127 // Kind implements Node.Kind. 128 func (n *Icon) Kind() ast.NodeKind { 129 return KindIcon 130 } 131 132 // NewIcon returns a new Paragraph node. 133 func NewIcon(name string) *Icon { 134 return &Icon{ 135 BaseInline: ast.BaseInline{}, 136 Name: []byte(name), 137 } 138 } 139 140 // IsIcon returns true if the given node implements the Icon interface, 141 // otherwise false. 142 func IsIcon(node ast.Node) bool { 143 _, ok := node.(*Icon) 144 return ok 145 } 146 147 // ColorPreview is an inline for a color preview 148 type ColorPreview struct { 149 ast.BaseInline 150 Color []byte 151 } 152 153 // Dump implements Node.Dump. 154 func (n *ColorPreview) Dump(source []byte, level int) { 155 m := map[string]string{} 156 m["Color"] = string(n.Color) 157 ast.DumpHelper(n, source, level, m, nil) 158 } 159 160 // KindColorPreview is the NodeKind for ColorPreview 161 var KindColorPreview = ast.NewNodeKind("ColorPreview") 162 163 // Kind implements Node.Kind. 164 func (n *ColorPreview) Kind() ast.NodeKind { 165 return KindColorPreview 166 } 167 168 // NewColorPreview returns a new Span node. 169 func NewColorPreview(color []byte) *ColorPreview { 170 return &ColorPreview{ 171 BaseInline: ast.BaseInline{}, 172 Color: color, 173 } 174 } 175 176 // IsColorPreview returns true if the given node implements the ColorPreview interface, 177 // otherwise false. 178 func IsColorPreview(node ast.Node) bool { 179 _, ok := node.(*ColorPreview) 180 return ok 181 } 182 183 const ( 184 AttentionNote string = "Note" 185 AttentionWarning string = "Warning" 186 ) 187 188 // Attention is an inline for a color preview 189 type Attention struct { 190 ast.BaseInline 191 AttentionType string 192 } 193 194 // Dump implements Node.Dump. 195 func (n *Attention) Dump(source []byte, level int) { 196 m := map[string]string{} 197 m["AttentionType"] = n.AttentionType 198 ast.DumpHelper(n, source, level, m, nil) 199 } 200 201 // KindAttention is the NodeKind for Attention 202 var KindAttention = ast.NewNodeKind("Attention") 203 204 // Kind implements Node.Kind. 205 func (n *Attention) Kind() ast.NodeKind { 206 return KindAttention 207 } 208 209 // NewAttention returns a new Attention node. 210 func NewAttention(attentionType string) *Attention { 211 return &Attention{ 212 BaseInline: ast.BaseInline{}, 213 AttentionType: attentionType, 214 } 215 }