github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/markup/markdown/ast.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package markdown
     7  
     8  import (
     9  	"strconv"
    10  
    11  	"github.com/yuin/goldmark/ast"
    12  )
    13  
    14  // Details is a block that contains Summary and details
    15  type Details struct {
    16  	ast.BaseBlock
    17  }
    18  
    19  // Dump implements Node.Dump .
    20  func (n *Details) Dump(source []byte, level int) {
    21  	ast.DumpHelper(n, source, level, nil, nil)
    22  }
    23  
    24  // KindDetails is the NodeKind for Details
    25  var KindDetails = ast.NewNodeKind("Details")
    26  
    27  // Kind implements Node.Kind.
    28  func (n *Details) Kind() ast.NodeKind {
    29  	return KindDetails
    30  }
    31  
    32  // NewDetails returns a new Paragraph node.
    33  func NewDetails() *Details {
    34  	return &Details{
    35  		BaseBlock: ast.BaseBlock{},
    36  	}
    37  }
    38  
    39  // IsDetails returns true if the given node implements the Details interface,
    40  // otherwise false.
    41  func IsDetails(node ast.Node) bool {
    42  	_, ok := node.(*Details)
    43  	return ok
    44  }
    45  
    46  // Summary is a block that contains the summary of details block
    47  type Summary struct {
    48  	ast.BaseBlock
    49  }
    50  
    51  // Dump implements Node.Dump .
    52  func (n *Summary) Dump(source []byte, level int) {
    53  	ast.DumpHelper(n, source, level, nil, nil)
    54  }
    55  
    56  // KindSummary is the NodeKind for Summary
    57  var KindSummary = ast.NewNodeKind("Summary")
    58  
    59  // Kind implements Node.Kind.
    60  func (n *Summary) Kind() ast.NodeKind {
    61  	return KindSummary
    62  }
    63  
    64  // NewSummary returns a new Summary node.
    65  func NewSummary() *Summary {
    66  	return &Summary{
    67  		BaseBlock: ast.BaseBlock{},
    68  	}
    69  }
    70  
    71  // IsSummary returns true if the given node implements the Summary interface,
    72  // otherwise false.
    73  func IsSummary(node ast.Node) bool {
    74  	_, ok := node.(*Summary)
    75  	return ok
    76  }
    77  
    78  // TaskCheckBoxListItem is a block that represents a list item of a markdown block with a checkbox
    79  type TaskCheckBoxListItem struct {
    80  	*ast.ListItem
    81  	IsChecked bool
    82  }
    83  
    84  // KindTaskCheckBoxListItem is the NodeKind for TaskCheckBoxListItem
    85  var KindTaskCheckBoxListItem = ast.NewNodeKind("TaskCheckBoxListItem")
    86  
    87  // Dump implements Node.Dump .
    88  func (n *TaskCheckBoxListItem) Dump(source []byte, level int) {
    89  	m := map[string]string{}
    90  	m["IsChecked"] = strconv.FormatBool(n.IsChecked)
    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  }