From 6903a774ecbbd05596adda5e2b5e18d58dd3a8f9 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Tue, 9 Jun 2026 21:09:39 +0200 Subject: bump all dependencies to their latest versions --- vendor/github.com/yuin/goldmark/ast/ast.go | 58 +++++++++++--- vendor/github.com/yuin/goldmark/ast/block.go | 93 +++++++++++++++++++++-- vendor/github.com/yuin/goldmark/ast/inline.go | 104 ++++++++++++++++++++++++-- 3 files changed, 230 insertions(+), 25 deletions(-) (limited to 'vendor/github.com/yuin/goldmark/ast') diff --git a/vendor/github.com/yuin/goldmark/ast/ast.go b/vendor/github.com/yuin/goldmark/ast/ast.go index 36ba606..e4bd205 100644 --- a/vendor/github.com/yuin/goldmark/ast/ast.go +++ b/vendor/github.com/yuin/goldmark/ast/ast.go @@ -42,7 +42,7 @@ func NewNodeKind(name string) NodeKind { // An Attribute is an attribute of the Node. type Attribute struct { Name []byte - Value interface{} + Value any } // A Node interface defines basic AST node functionalities. @@ -53,6 +53,15 @@ type Node interface { // Kind returns a kind of this node. Kind() NodeKind + // Pos returns a position of this node in a source. + // If this node position is not defined, Pos returns -1. + Pos() int + + // SetPos sets a position of this node in a source. + // Some node may ignore this method. For example, Paragraph node ignores this method because + // it calculates its position from its lines. + SetPos(v int) + // NextSibling returns a next sibling node of this node. NextSibling() Node @@ -152,20 +161,20 @@ type Node interface { IsRaw() bool // SetAttribute sets the given value to the attributes. - SetAttribute(name []byte, value interface{}) + SetAttribute(name []byte, value any) // SetAttributeString sets the given value to the attributes. - SetAttributeString(name string, value interface{}) + SetAttributeString(name string, value any) // Attribute returns a (attribute value, true) if an attribute // associated with the given name is found, otherwise // (nil, false) - Attribute(name []byte) (interface{}, bool) + Attribute(name []byte) (any, bool) // AttributeString returns a (attribute value, true) if an attribute // associated with the given name is found, otherwise // (nil, false) - AttributeString(name string) (interface{}, bool) + AttributeString(name string) (any, bool) // Attributes returns a list of attributes. // This may be a nil if there are no attributes. @@ -175,6 +184,23 @@ type Node interface { RemoveAttributes() } +type pos struct { + has bool + value int +} + +func (p *pos) Pos() int { + if p.has { + return p.value + } + return -1 +} + +func (p *pos) SetPos(v int) { + p.has = true + p.value = v +} + // A BaseNode struct implements the Node interface partialliy. type BaseNode struct { firstChild Node @@ -184,6 +210,7 @@ type BaseNode struct { prev Node childCount int attributes []Attribute + pos pos } func ensureIsolated(v Node) { @@ -192,6 +219,16 @@ func ensureIsolated(v Node) { } } +// Pos implements Node.Pos . +func (n *BaseNode) Pos() int { + return n.pos.Pos() +} + +// SetPos implements Node.SetPos . +func (n *BaseNode) SetPos(v int) { + n.pos.SetPos(v) +} + // HasChildren implements Node.HasChildren . func (n *BaseNode) HasChildren() bool { return n.firstChild != nil @@ -397,7 +434,7 @@ func (n *BaseNode) Text(source []byte) []byte { } // SetAttribute implements Node.SetAttribute. -func (n *BaseNode) SetAttribute(name []byte, value interface{}) { +func (n *BaseNode) SetAttribute(name []byte, value any) { if n.attributes == nil { n.attributes = make([]Attribute, 0, 10) } else { @@ -413,12 +450,12 @@ func (n *BaseNode) SetAttribute(name []byte, value interface{}) { } // SetAttributeString implements Node.SetAttributeString. -func (n *BaseNode) SetAttributeString(name string, value interface{}) { +func (n *BaseNode) SetAttributeString(name string, value any) { n.SetAttribute(util.StringToReadOnlyBytes(name), value) } // Attribute implements Node.Attribute. -func (n *BaseNode) Attribute(name []byte) (interface{}, bool) { +func (n *BaseNode) Attribute(name []byte) (any, bool) { if n.attributes == nil { return nil, false } @@ -431,7 +468,7 @@ func (n *BaseNode) Attribute(name []byte) (interface{}, bool) { } // AttributeString implements Node.AttributeString. -func (n *BaseNode) AttributeString(s string) (interface{}, bool) { +func (n *BaseNode) AttributeString(s string) (any, bool) { return n.Attribute(util.StringToReadOnlyBytes(s)) } @@ -453,9 +490,10 @@ func DumpHelper(v Node, source []byte, level int, kv map[string]string, cb func( indent := strings.Repeat(" ", level) fmt.Printf("%s%s {\n", indent, name) indent2 := strings.Repeat(" ", level+1) + fmt.Printf("%sPos: %d\n", indent2, v.Pos()) if v.Type() == TypeBlock { fmt.Printf("%sRawText: \"", indent2) - for i := 0; i < v.Lines().Len(); i++ { + for i := range v.Lines().Len() { line := v.Lines().At(i) fmt.Printf("%s", line.Value(source)) } diff --git a/vendor/github.com/yuin/goldmark/ast/block.go b/vendor/github.com/yuin/goldmark/ast/block.go index efeea08..806f99a 100644 --- a/vendor/github.com/yuin/goldmark/ast/block.go +++ b/vendor/github.com/yuin/goldmark/ast/block.go @@ -48,7 +48,7 @@ func (b *BaseBlock) SetLines(v *textm.Segments) { type Document struct { BaseBlock - meta map[string]interface{} + meta map[string]any } // KindDocument is a NodeKind of the Document node. @@ -64,6 +64,11 @@ func (n *Document) Type() NodeType { return TypeDocument } +// Pos implements Node.Pos. +func (n *Document) Pos() int { + return 0 +} + // Kind implements Node.Kind. func (n *Document) Kind() NodeKind { return KindDocument @@ -75,17 +80,17 @@ func (n *Document) OwnerDocument() *Document { } // Meta returns metadata of this document. -func (n *Document) Meta() map[string]interface{} { +func (n *Document) Meta() map[string]any { if n.meta == nil { - n.meta = map[string]interface{}{} + n.meta = map[string]any{} } return n.meta } // SetMeta sets given metadata to this document. -func (n *Document) SetMeta(meta map[string]interface{}) { +func (n *Document) SetMeta(meta map[string]any) { if n.meta == nil { - n.meta = map[string]interface{}{} + n.meta = map[string]any{} } for k, v := range meta { n.meta[k] = v @@ -93,9 +98,9 @@ func (n *Document) SetMeta(meta map[string]interface{}) { } // AddMeta adds given metadata to this document. -func (n *Document) AddMeta(key string, value interface{}) { +func (n *Document) AddMeta(key string, value any) { if n.meta == nil { - n.meta = map[string]interface{}{} + n.meta = map[string]any{} } n.meta[key] = value } @@ -119,6 +124,14 @@ func (n *TextBlock) Dump(source []byte, level int) { DumpHelper(n, source, level, nil, nil) } +// Pos implements Node.Pos. +func (n *TextBlock) Pos() int { + if n.lines.Len() == 0 { + return -1 + } + return n.lines.At(0).Start +} + // KindTextBlock is a NodeKind of the TextBlock node. var KindTextBlock = NewNodeKind("TextBlock") @@ -151,6 +164,14 @@ func (n *Paragraph) Dump(source []byte, level int) { DumpHelper(n, source, level, nil, nil) } +// Pos implements Node.Pos. +func (n *Paragraph) Pos() int { + if n.lines.Len() == 0 { + return -1 + } + return n.lines.At(0).Start +} + // KindParagraph is a NodeKind of the Paragraph node. var KindParagraph = NewNodeKind("Paragraph") @@ -499,8 +520,9 @@ func (n *HTMLBlock) Dump(source []byte, level int) { indent := strings.Repeat(" ", level) fmt.Printf("%s%s {\n", indent, "HTMLBlock") indent2 := strings.Repeat(" ", level+1) + fmt.Printf("%sPos: %d\n", indent2, n.Pos()) fmt.Printf("%sRawText: \"", indent2) - for i := 0; i < n.Lines().Len(); i++ { + for i := range n.Lines().Len() { s := n.Lines().At(i) fmt.Print(string(source[s.Start:s.Stop])) } @@ -543,3 +565,58 @@ func NewHTMLBlock(typ HTMLBlockType) *HTMLBlock { ClosureLine: textm.NewSegment(-1, -1), } } + +// A LinkReferenceDefinition struct represents a list of Markdown text. +type LinkReferenceDefinition struct { + BaseBlock + + // Label is a label of this link reference definition. + Label []byte + + // Destination is a destination of this link reference definition. + Destination []byte + + // Title is a title of this link reference definition. + Title []byte +} + +// IsRaw implements Node.IsRaw. +func (l *LinkReferenceDefinition) IsRaw() bool { + return true +} + +// Pos implements Node.Pos. +func (l *LinkReferenceDefinition) Pos() int { + if l.lines.Len() == 0 { + return -1 + } + return l.lines.At(0).Start +} + +// Dump implements Node.Dump. +func (l *LinkReferenceDefinition) Dump(source []byte, level int) { + m := map[string]string{ + "Label": string(l.Label), + "Destination": string(l.Destination), + "Title": string(l.Title), + } + DumpHelper(l, source, level, m, nil) +} + +// KindLinkReferenceDefinition is a NodeKind of the LinkReferenceDefinition node. +var KindLinkReferenceDefinition = NewNodeKind("LinkReferenceDefinition") + +// Kind implements Node.Kind. +func (l *LinkReferenceDefinition) Kind() NodeKind { + return KindLinkReferenceDefinition +} + +// NewLinkReferenceDefinition returns a new LinkReferenceDefinition node. +func NewLinkReferenceDefinition(label, destination, title []byte) *LinkReferenceDefinition { + return &LinkReferenceDefinition{ + BaseBlock: BaseBlock{}, + Label: label, + Destination: destination, + Title: title, + } +} diff --git a/vendor/github.com/yuin/goldmark/ast/inline.go b/vendor/github.com/yuin/goldmark/ast/inline.go index 613eb1e..732329c 100644 --- a/vendor/github.com/yuin/goldmark/ast/inline.go +++ b/vendor/github.com/yuin/goldmark/ast/inline.go @@ -80,6 +80,11 @@ func textFlagsString(flags uint8) string { func (n *Text) Inline() { } +// Pos implements Node.Pos. +func (n *Text) Pos() int { + return n.Segment.Start +} + // SoftLineBreak returns true if this node ends with a new line, // otherwise false. func (n *Text) SoftLineBreak() bool { @@ -157,11 +162,14 @@ func (n *Text) Value(source []byte) []byte { // Dump implements Node.Dump. func (n *Text) Dump(source []byte, level int) { + m := map[string]string{ + "Value": "\"" + strings.TrimRight(string(n.Value(source)), "\n") + "\"", + } fs := textFlagsString(n.flags) if len(fs) != 0 { - fs = "(" + fs + ")" + m["Flags"] = fs } - fmt.Printf("%sText%s: \"%s\"\n", strings.Repeat(" ", level), fs, strings.TrimRight(string(n.Value(source)), "\n")) + DumpHelper(n, source, level, m, nil) } // KindText is a NodeKind of the Text node. @@ -235,6 +243,12 @@ type String struct { func (n *String) Inline() { } +// Pos implements Node.Pos. +// String node does not have a position because it is not associated with a source text. +func (n *String) Pos() int { + return -1 +} + // IsRaw returns true if this text should be rendered without unescaping // back slash escapes and resolving references. func (n *String) IsRaw() bool { @@ -376,12 +390,59 @@ type baseLink struct { // Title is a title of this link. Title []byte + + // Reference is a reference of this link. This field is used for reference links. + // If this link is not a reference link, this field is nil. + Reference *ReferenceLink } // Inline implements Inline.Inline. func (n *baseLink) Inline() { } +// ReferenceLinkType defines a kind of reference link. +type ReferenceLinkType int + +const ( + // ReferenceLinkFull indicates that a reference link has a full reference like [foo][bar]. + ReferenceLinkFull ReferenceLinkType = iota + 1 + // ReferenceLinkCollapsed indicates that a reference link has a collapsed reference like [foo][]. + ReferenceLinkCollapsed + // ReferenceLinkShortcut indicates that a reference link has a shortcut reference like [foo]. + ReferenceLinkShortcut +) + +// String returns a string representation of this reference link type. +func (t ReferenceLinkType) String() string { + switch t { + case ReferenceLinkFull: + return "Full" + case ReferenceLinkCollapsed: + return "Collapsed" + case ReferenceLinkShortcut: + return "Shortcut" + default: + return fmt.Sprintf("Unknown(%d)", t) + } +} + +// ReferenceLink struct represents a reference link of the Markdown text. +type ReferenceLink struct { + // Type is a kind of this reference link. + Type ReferenceLinkType + + // Value is a value of this reference link. + Value []byte +} + +// NewReferenceLink returns a new ReferenceLink with the given type and value. +func NewReferenceLink(typ ReferenceLinkType, value []byte) *ReferenceLink { + return &ReferenceLink{ + Type: typ, + Value: value, + } +} + // A Link struct represents a link of the Markdown text. type Link struct { baseLink @@ -391,8 +452,22 @@ type Link struct { func (n *Link) Dump(source []byte, level int) { m := map[string]string{} m["Destination"] = string(n.Destination) - m["Title"] = string(n.Title) - DumpHelper(n, source, level, m, nil) + if len(n.Title) != 0 { + m["Title"] = string(n.Title) + } + cb := func(int) {} + if n.Reference != nil { + cb = func(level int) { + indent := strings.Repeat(" ", level) + fmt.Printf("%sReference {\n", indent) + indent2 := strings.Repeat(" ", level+1) + fmt.Printf("%sType : %s\n", indent2, n.Reference.Type.String()) + fmt.Printf("%sValue : %s\n", indent2, string(n.Reference.Value)) + fmt.Printf("%s}\n", indent) + + } + } + DumpHelper(n, source, level, m, cb) } // KindLink is a NodeKind of the Link node. @@ -422,8 +497,22 @@ type Image struct { func (n *Image) Dump(source []byte, level int) { m := map[string]string{} m["Destination"] = string(n.Destination) - m["Title"] = string(n.Title) - DumpHelper(n, source, level, m, nil) + if len(n.Title) != 0 { + m["Title"] = string(n.Title) + } + cb := func(int) {} + if n.Reference != nil { + cb = func(level int) { + indent := strings.Repeat(" ", level) + fmt.Printf("%sReference {\n", indent) + indent2 := strings.Repeat(" ", level+1) + fmt.Printf("%sType : %s\n", indent2, n.Reference.Type.String()) + fmt.Printf("%sValue : %s\n", indent2, string(n.Reference.Value)) + fmt.Printf("%s}\n", indent) + + } + } + DumpHelper(n, source, level, m, cb) } // KindImage is a NodeKind of the Image node. @@ -443,6 +532,7 @@ func NewImage(link *Link) *Image { } c.Destination = link.Destination c.Title = link.Title + c.Reference = link.Reference for n := link.FirstChild(); n != nil; { next := n.NextSibling() link.RemoveChild(link, n) @@ -542,7 +632,7 @@ func (n *RawHTML) Inline() {} func (n *RawHTML) Dump(source []byte, level int) { m := map[string]string{} t := []string{} - for i := 0; i < n.Segments.Len(); i++ { + for i := range n.Segments.Len() { segment := n.Segments.At(i) t = append(t, string(segment.Value(source))) } -- cgit v1.3.1