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/.gitignore | 2 + vendor/github.com/yuin/goldmark/README.md | 6 + 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 +++++++++++++++-- .../yuin/goldmark/extension/ast/definition_list.go | 16 +++ .../yuin/goldmark/extension/ast/table.go | 1 + .../yuin/goldmark/extension/ast/tasklist.go | 1 + .../yuin/goldmark/extension/definition_list.go | 2 +- .../github.com/yuin/goldmark/extension/footnote.go | 2 +- .../github.com/yuin/goldmark/extension/linkify.go | 9 +- vendor/github.com/yuin/goldmark/extension/table.go | 22 +++- .../yuin/goldmark/extension/typographer.go | 2 +- vendor/github.com/yuin/goldmark/markdown.go | 2 +- .../github.com/yuin/goldmark/parser/attribute.go | 18 +-- .../github.com/yuin/goldmark/parser/atx_heading.go | 129 ++++++++------------- .../github.com/yuin/goldmark/parser/delimiter.go | 1 + .../github.com/yuin/goldmark/parser/fcode_block.go | 13 +-- .../github.com/yuin/goldmark/parser/html_block.go | 3 - vendor/github.com/yuin/goldmark/parser/link.go | 23 ++-- vendor/github.com/yuin/goldmark/parser/link_ref.go | 72 +++++++----- vendor/github.com/yuin/goldmark/parser/list.go | 14 +-- .../github.com/yuin/goldmark/parser/list_item.go | 4 +- .../github.com/yuin/goldmark/parser/paragraph.go | 7 +- vendor/github.com/yuin/goldmark/parser/parser.go | 73 ++++++++---- vendor/github.com/yuin/goldmark/parser/raw_html.go | 6 +- .../yuin/goldmark/parser/setext_headings.go | 1 + .../github.com/yuin/goldmark/renderer/html/html.go | 34 +++--- .../github.com/yuin/goldmark/renderer/renderer.go | 14 +-- .../github.com/yuin/goldmark/util/html5entities.go | 2 +- .../yuin/goldmark/util/unicode_case_folding.go | 2 +- vendor/github.com/yuin/goldmark/util/util.go | 88 +++++++------- 32 files changed, 542 insertions(+), 282 deletions(-) (limited to 'vendor/github.com') diff --git a/vendor/github.com/yuin/goldmark/.gitignore b/vendor/github.com/yuin/goldmark/.gitignore index 06c135f..abcfac3 100644 --- a/vendor/github.com/yuin/goldmark/.gitignore +++ b/vendor/github.com/yuin/goldmark/.gitignore @@ -17,3 +17,5 @@ fuzz/corpus fuzz/crashers fuzz/suppressions fuzz/fuzz-fuzz.zip + +cmd diff --git a/vendor/github.com/yuin/goldmark/README.md b/vendor/github.com/yuin/goldmark/README.md index 1922fd0..9cf4110 100644 --- a/vendor/github.com/yuin/goldmark/README.md +++ b/vendor/github.com/yuin/goldmark/README.md @@ -12,6 +12,8 @@ goldmark is compliant with CommonMark 0.31.2. - [goldmark playground](https://yuin.github.io/goldmark/playground/) : Try goldmark online. This playground is built with WASM(5-10MB). +There is also a Rust version of goldmark: [rushdown](https://github.com/yuin/rushdown) + Motivation ---------------------- I needed a Markdown parser for Go that satisfies the following requirements: @@ -497,6 +499,10 @@ Extensions - [goldmark-wiki-table](https://github.com/movsb/goldmark-wiki-table): Adds support for embedding Wiki Tables. - [goldmark-tgmd](https://github.com/Mad-Pixels/goldmark-tgmd): A Telegram markdown renderer that can be passed to `goldmark.WithRenderer()`. - [goldmark-treeblood](https://github.com/Wyatt915/goldmark-treeblood): Renders $\LaTeX$ expressions as MathML (pure Go, no external dependencies). +- [goldmark-subtext](https://github.com/zeozeozeo/goldmark-subtext): Support for Discord-style markdown subtexts +- [goldmark-customtag](https://github.com/tendstofortytwo/goldmark-customtag): Allows you to define custom block tags. +- [goldmark-cjk-friendly](https://github.com/tats-u/goldmark-cjk-friendly): Port of npm package [`remark-cjk-friendly` / `markdown-it-cjk-friendly`](https://github.com/tats-u/markdown-cjk-friendly) to goldmark. Similar to the [CJK extension](#cjk-extension) (`WithEscapedSpace`), but you do not need to explicitly add `\ ` around `*` and `**`. You can combine this with the [CJK extension](#cjk-extension). +- [goldmark-chart](https://github.com/TheGreatRambler/goldmark-chart): Generate static ChartJS charts using the simple [Markvis](https://markvis.js.org/#/) format. ### Loading extensions at runtime [goldmark-dynamic](https://github.com/yuin/goldmark-dynamic) allows you to write a goldmark extension in Lua and load it at runtime without re-compilation. 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))) } diff --git a/vendor/github.com/yuin/goldmark/extension/ast/definition_list.go b/vendor/github.com/yuin/goldmark/extension/ast/definition_list.go index 1beffb3..0ff7412 100644 --- a/vendor/github.com/yuin/goldmark/extension/ast/definition_list.go +++ b/vendor/github.com/yuin/goldmark/extension/ast/definition_list.go @@ -17,6 +17,14 @@ func (n *DefinitionList) Dump(source []byte, level int) { gast.DumpHelper(n, source, level, nil, nil) } +// Pos implements Node.Pos. +func (n *DefinitionList) Pos() int { + if n.FirstChild() != nil { + return n.FirstChild().Pos() + } + return -1 +} + // KindDefinitionList is a NodeKind of the DefinitionList node. var KindDefinitionList = gast.NewNodeKind("DefinitionList") @@ -44,6 +52,14 @@ func (n *DefinitionTerm) Dump(source []byte, level int) { gast.DumpHelper(n, source, level, nil, nil) } +// Pos implements Node.Pos. +func (n *DefinitionTerm) Pos() int { + if n.Lines().Len() == 0 { + return -1 + } + return n.Lines().At(0).Start +} + // KindDefinitionTerm is a NodeKind of the DefinitionTerm node. var KindDefinitionTerm = gast.NewNodeKind("DefinitionTerm") diff --git a/vendor/github.com/yuin/goldmark/extension/ast/table.go b/vendor/github.com/yuin/goldmark/extension/ast/table.go index 4142e33..ba87048 100644 --- a/vendor/github.com/yuin/goldmark/extension/ast/table.go +++ b/vendor/github.com/yuin/goldmark/extension/ast/table.go @@ -123,6 +123,7 @@ func (n *TableHeader) Dump(source []byte, level int) { // NewTableHeader returns a new TableHeader node. func NewTableHeader(row *TableRow) *TableHeader { n := &TableHeader{} + n.SetPos(row.Pos()) for c := row.FirstChild(); c != nil; { next := c.NextSibling() n.AppendChild(n, c) diff --git a/vendor/github.com/yuin/goldmark/extension/ast/tasklist.go b/vendor/github.com/yuin/goldmark/extension/ast/tasklist.go index 670cc14..16abf95 100644 --- a/vendor/github.com/yuin/goldmark/extension/ast/tasklist.go +++ b/vendor/github.com/yuin/goldmark/extension/ast/tasklist.go @@ -2,6 +2,7 @@ package ast import ( "fmt" + gast "github.com/yuin/goldmark/ast" ) diff --git a/vendor/github.com/yuin/goldmark/extension/definition_list.go b/vendor/github.com/yuin/goldmark/extension/definition_list.go index 3e64dcf..b7a86c0 100644 --- a/vendor/github.com/yuin/goldmark/extension/definition_list.go +++ b/vendor/github.com/yuin/goldmark/extension/definition_list.go @@ -130,7 +130,7 @@ func (b *definitionDescriptionParser) Open( if para != nil { lines := para.Lines() l := lines.Len() - for i := 0; i < l; i++ { + for i := range l { term := ast.NewDefinitionTerm() segment := lines.At(i) term.Lines().Append(segment.TrimRightSpace(reader.Source())) diff --git a/vendor/github.com/yuin/goldmark/extension/footnote.go b/vendor/github.com/yuin/goldmark/extension/footnote.go index 2e22526..30eb85c 100644 --- a/vendor/github.com/yuin/goldmark/extension/footnote.go +++ b/vendor/github.com/yuin/goldmark/extension/footnote.go @@ -321,7 +321,7 @@ func NewFootnoteConfig() FootnoteConfig { } // SetOption implements renderer.SetOptioner. -func (c *FootnoteConfig) SetOption(name renderer.OptionName, value interface{}) { +func (c *FootnoteConfig) SetOption(name renderer.OptionName, value any) { switch name { case optFootnoteIDPrefixFunction: c.IDPrefixFunction = value.(func(gast.Node) []byte) diff --git a/vendor/github.com/yuin/goldmark/extension/linkify.go b/vendor/github.com/yuin/goldmark/extension/linkify.go index ad88933..f76e31d 100644 --- a/vendor/github.com/yuin/goldmark/extension/linkify.go +++ b/vendor/github.com/yuin/goldmark/extension/linkify.go @@ -32,7 +32,7 @@ const ( ) // SetOption implements SetOptioner. -func (c *LinkifyConfig) SetOption(name parser.OptionName, value interface{}) { +func (c *LinkifyConfig) SetOption(name parser.OptionName, value any) { switch name { case optLinkifyAllowedProtocols: c.AllowedProtocols = value.([][]byte) @@ -211,9 +211,10 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont } else if lastChar == ')' { closing := 0 for i := m[1] - 1; i >= m[0]; i-- { - if line[i] == ')' { + switch line[i] { + case ')': closing++ - } else if line[i] == '(' { + case '(': closing-- } } @@ -254,7 +255,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont } at := bytes.IndexByte(line, '@') m = []int{0, stop, at, stop - 1} - if m == nil || bytes.IndexByte(line[m[2]:m[3]], '.') < 0 { + if bytes.IndexByte(line[m[2]:m[3]], '.') < 0 { return nil } lastChar := line[m[1]-1] diff --git a/vendor/github.com/yuin/goldmark/extension/table.go b/vendor/github.com/yuin/goldmark/extension/table.go index ee782a2..1d74182 100644 --- a/vendor/github.com/yuin/goldmark/extension/table.go +++ b/vendor/github.com/yuin/goldmark/extension/table.go @@ -68,7 +68,7 @@ func NewTableConfig() TableConfig { } // SetOption implements renderer.SetOptioner. -func (c *TableConfig) SetOption(name renderer.OptionName, value interface{}) { +func (c *TableConfig) SetOption(name renderer.OptionName, value any) { switch name { case optTableCellAlignMethod: c.TableCellAlignMethod = value.(TableCellAlignMethod) @@ -125,12 +125,16 @@ func isTableDelim(bs []byte) bool { if w, _ := util.IndentWidth(bs, 0); w > 3 { return false } + allSep := true for _, b := range bs { + if b != '-' { + allSep = false + } if !(util.IsSpace(b) || b == '-' || b == '|' || b == ':') { return false } } - return true + return !allSep } var tableDelimLeft = regexp.MustCompile(`^\s*\:\-+\s*$`) @@ -150,6 +154,7 @@ func NewTableParagraphTransformer() parser.ParagraphTransformer { } func (b *tableParagraphTransformer) Transform(node *gast.Paragraph, reader text.Reader, pc parser.Context) { + ppos := node.Pos() lines := node.Lines() if lines.Len() < 2 { return @@ -165,6 +170,7 @@ func (b *tableParagraphTransformer) Transform(node *gast.Paragraph, reader text. } table := ast.NewTable() table.Alignments = alignments + table.SetPos(ppos) table.AppendChild(table, ast.NewTableHeader(header)) for j := i + 1; j < lines.Len(); j++ { table.AppendChild(table, b.parseRow(lines.At(j), alignments, false, reader, pc)) @@ -183,6 +189,7 @@ func (b *tableParagraphTransformer) Transform(node *gast.Paragraph, reader text. func (b *tableParagraphTransformer) parseRow(segment text.Segment, alignments []ast.Alignment, isHeader bool, reader text.Reader, pc parser.Context) *ast.TableRow { + npos := segment source := reader.Source() segment = segment.TrimLeftSpace(source) segment = segment.TrimRightSpace(source) @@ -190,6 +197,7 @@ func (b *tableParagraphTransformer) parseRow(segment text.Segment, pos := 0 limit := len(line) row := ast.NewTableRow(alignments) + row.SetPos(npos.Start) if len(line) > 0 && line[pos] == '|' { pos++ } @@ -209,6 +217,7 @@ func (b *tableParagraphTransformer) parseRow(segment text.Segment, var escapedCell *escapedPipeCell node := ast.NewTableCell() + node.SetPos(npos.Start + pos - npos.Padding) node.Alignment = alignment hasBacktick := false closure := pos @@ -223,7 +232,7 @@ func (b *tableParagraphTransformer) parseRow(segment text.Segment, if escapedCell == nil { escapedCell = &escapedPipeCell{node, []int{}, false} escapedList := pc.ComputeIfAbsent(escapedPipeCellListKey, - func() interface{} { + func() any { return []*escapedPipeCell{} }).([]*escapedPipeCell) escapedList = append(escapedList, escapedCell) @@ -502,7 +511,12 @@ func (r *TableHTMLRenderer) renderTableCell( v, ok := n.AttributeString("style") var cob util.CopyOnWriteBuffer if ok { - cob = util.NewCopyOnWriteBuffer(v.([]byte)) + switch v := v.(type) { + case []byte: + cob = util.NewCopyOnWriteBuffer(v) + case string: + cob = util.NewCopyOnWriteBuffer([]byte(v)) + } cob.AppendByte(';') } style := fmt.Sprintf("text-align:%s", n.Alignment.String()) diff --git a/vendor/github.com/yuin/goldmark/extension/typographer.go b/vendor/github.com/yuin/goldmark/extension/typographer.go index 44c15eb..3a3f106 100644 --- a/vendor/github.com/yuin/goldmark/extension/typographer.go +++ b/vendor/github.com/yuin/goldmark/extension/typographer.go @@ -83,7 +83,7 @@ func newDefaultSubstitutions() [][]byte { } // SetOption implements SetOptioner. -func (b *TypographerConfig) SetOption(name parser.OptionName, value interface{}) { +func (b *TypographerConfig) SetOption(name parser.OptionName, value any) { switch name { case optTypographicSubstitutions: b.Substitutions = value.([][]byte) diff --git a/vendor/github.com/yuin/goldmark/markdown.go b/vendor/github.com/yuin/goldmark/markdown.go index 8ebaa5a..5fec7a6 100644 --- a/vendor/github.com/yuin/goldmark/markdown.go +++ b/vendor/github.com/yuin/goldmark/markdown.go @@ -45,7 +45,7 @@ type Markdown interface { // SetParser sets a Parser to this object. SetParser(parser.Parser) - // Parser returns a Renderer that will be used for conversion. + // Renderer returns a Renderer that will be used for conversion. Renderer() renderer.Renderer // SetRenderer sets a Renderer to this object. diff --git a/vendor/github.com/yuin/goldmark/parser/attribute.go b/vendor/github.com/yuin/goldmark/parser/attribute.go index 42985f4..5647a51 100644 --- a/vendor/github.com/yuin/goldmark/parser/attribute.go +++ b/vendor/github.com/yuin/goldmark/parser/attribute.go @@ -15,14 +15,14 @@ var attrNameClass = []byte("class") // An Attribute is an attribute of the markdown elements. type Attribute struct { Name []byte - Value interface{} + Value any } // An Attributes is a collection of attributes. type Attributes []Attribute // Find returns a (value, true) if an attribute correspond with given name is found, otherwise (nil, false). -func (as Attributes) Find(name []byte) (interface{}, bool) { +func (as Attributes) Find(name []byte) (any, bool) { for _, a := range as { if bytes.Equal(a.Name, name) { return a.Value, true @@ -31,7 +31,7 @@ func (as Attributes) Find(name []byte) (interface{}, bool) { return nil, false } -func (as Attributes) findUpdate(name []byte, cb func(v interface{}) interface{}) bool { +func (as Attributes) findUpdate(name []byte, cb func(v any) any) bool { for i, a := range as { if bytes.Equal(a.Name, name) { as[i].Value = cb(a.Value) @@ -64,7 +64,7 @@ func ParseAttributes(reader text.Reader) (Attributes, bool) { return nil, false } if bytes.Equal(attr.Name, attrNameClass) { - if !attrs.findUpdate(attrNameClass, func(v interface{}) interface{} { + if !attrs.findUpdate(attrNameClass, func(v any) any { ret := make([]byte, 0, len(v.([]byte))+1+len(attr.Value.([]byte))) ret = append(ret, v.([]byte)...) return append(append(ret, ' '), attr.Value.([]byte)...) @@ -142,10 +142,10 @@ func parseAttribute(reader text.Reader) (Attribute, bool) { return Attribute{Name: name, Value: value}, true } -func parseAttributeValue(reader text.Reader) (interface{}, bool) { +func parseAttributeValue(reader text.Reader) (any, bool) { reader.SkipSpaces() c := reader.Peek() - var value interface{} + var value any var ok bool switch c { case text.EOF: @@ -169,9 +169,9 @@ func parseAttributeValue(reader text.Reader) (interface{}, bool) { return value, true } -func parseAttributeArray(reader text.Reader) ([]interface{}, bool) { +func parseAttributeArray(reader text.Reader) ([]any, bool) { reader.Advance(1) // skip [ - ret := []interface{}{} + ret := []any{} for i := 0; ; i++ { c := reader.Peek() comma := false @@ -298,7 +298,7 @@ var bytesTrue = []byte("true") var bytesFalse = []byte("false") var bytesNull = []byte("null") -func parseAttributeOthers(reader text.Reader) (interface{}, bool) { +func parseAttributeOthers(reader text.Reader) (any, bool) { line, _ := reader.PeekLine() c := line[0] if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || diff --git a/vendor/github.com/yuin/goldmark/parser/atx_heading.go b/vendor/github.com/yuin/goldmark/parser/atx_heading.go index dae5e84..b5c6df0 100644 --- a/vendor/github.com/yuin/goldmark/parser/atx_heading.go +++ b/vendor/github.com/yuin/goldmark/parser/atx_heading.go @@ -13,7 +13,7 @@ type HeadingConfig struct { } // SetOption implements SetOptioner. -func (b *HeadingConfig) SetOption(name OptionName, _ interface{}) { +func (b *HeadingConfig) SetOption(name OptionName, _ any) { switch name { case optAutoHeadingID: b.AutoHeadingID = true @@ -98,69 +98,47 @@ func (b *atxHeadingParser) Open(parent ast.Node, reader text.Reader, pc Context) if l == 0 { return nil, NoChildren } - start := i + l - if start >= len(line) { - start = len(line) - 1 - } - origstart := start - stop := len(line) - util.TrimRightSpaceLength(line) + start := min(i+l, len(line)-1) node := ast.NewHeading(level) - parsed := false - if b.Attribute { // handles special case like ### heading ### {#id} - start-- - closureClose := -1 - closureOpen := -1 - for j := start; j < stop; { - c := line[j] - if util.IsEscapedPunctuation(line, j) { - j += 2 - } else if util.IsSpace(c) && j < stop-1 && line[j+1] == '#' { - closureOpen = j + 1 - k := j + 1 - for ; k < stop && line[k] == '#'; k++ { - } - closureClose = k - break - } else { - j++ - } + hl := text.NewSegment( + segment.Start+start-segment.Padding, + segment.Start+len(line)-segment.Padding) + hl = hl.TrimRightSpace(reader.Source()) + if hl.Len() == 0 { + reader.AdvanceToEOL() + return node, NoChildren + } + + if b.Attribute { + node.Lines().Append(hl) + parseLastLineAttributes(node, reader, pc) + hl = node.Lines().At(0) + node.Lines().Clear() + } + + // handle closing sequence of '#' characters + line = hl.Value(reader.Source()) + stop := len(line) + if stop == 0 { // empty headings like '##[space]' + stop = 0 + } else { + i = stop - 1 + for ; line[i] == '#' && i > 0; i-- { } - if closureClose > 0 { - reader.Advance(closureClose) - attrs, ok := ParseAttributes(reader) - rest, _ := reader.PeekLine() - parsed = ok && util.IsBlank(rest) - if parsed { - for _, attr := range attrs { - node.SetAttribute(attr.Name, attr.Value) - } - node.Lines().Append(text.NewSegment( - segment.Start+start+1-segment.Padding, - segment.Start+closureOpen-segment.Padding)) - } + if i == 0 && line[0] == '#' { // empty headings like '### ###' + reader.AdvanceToEOL() + return node, NoChildren } - } - if !parsed { - start = origstart - stop := len(line) - util.TrimRightSpaceLength(line) - if stop <= start { // empty headings like '##[space]' - stop = start - } else { - i = stop - 1 - for ; line[i] == '#' && i >= start; i-- { - } - if i != stop-1 && !util.IsSpace(line[i]) { - i = stop - 1 - } - i++ + if i != stop-1 && util.IsSpace(line[i]) { stop = i - } - - if len(util.TrimRight(line[start:stop], []byte{'#'})) != 0 { // empty heading like '### ###' - node.Lines().Append(text.NewSegment(segment.Start+start-segment.Padding, segment.Start+stop-segment.Padding)) + stop -= util.TrimRightSpaceLength(line[0:stop]) } } + hl.Stop = hl.Start + stop + node.Lines().Append(hl) + reader.AdvanceToEOL() + return node, NoChildren } @@ -169,13 +147,6 @@ func (b *atxHeadingParser) Continue(node ast.Node, reader text.Reader, pc Contex } func (b *atxHeadingParser) Close(node ast.Node, reader text.Reader, pc Context) { - if b.Attribute { - _, ok := node.AttributeString("id") - if !ok { - parseLastLineAttributes(node, reader, pc) - } - } - if b.AutoHeadingID { id, ok := node.AttributeString("id") if !ok { @@ -205,7 +176,7 @@ func generateAutoHeadingID(node *ast.Heading, reader text.Reader, pc Context) { node.SetAttribute(attrNameID, headingID) } -func parseLastLineAttributes(node ast.Node, reader text.Reader, pc Context) { +func parseLastLineAttributes(node ast.Node, reader text.Reader, _ Context) { lastIndex := node.Lines().Len() - 1 if lastIndex < 0 { // empty headings return @@ -213,36 +184,36 @@ func parseLastLineAttributes(node ast.Node, reader text.Reader, pc Context) { lastLine := node.Lines().At(lastIndex) line := lastLine.Value(reader.Source()) lr := text.NewReader(line) - var attrs Attributes - var ok bool var start text.Segment var sl int - var end text.Segment for { c := lr.Peek() - if c == text.EOF { + if c == text.EOF || c == '\n' { break } if c == '\\' { lr.Advance(1) - if lr.Peek() == '{' { + if util.IsPunct(lr.Peek()) { lr.Advance(1) } continue } if c == '{' { sl, start = lr.Position() - attrs, ok = ParseAttributes(lr) - _, end = lr.Position() + attrs, ok := ParseAttributes(lr) + if ok { + if nl, _ := lr.PeekLine(); nl == nil || util.IsBlank(nl) { + for _, attr := range attrs { + node.SetAttribute(attr.Name, attr.Value) + } + lastLine.Stop = lastLine.Start + start.Start + lastLine = lastLine.TrimRightSpace(reader.Source()) + node.Lines().Set(lastIndex, lastLine) + return + } + } lr.SetPosition(sl, start) } lr.Advance(1) } - if ok && util.IsBlank(line[end.Start:]) { - for _, attr := range attrs { - node.SetAttribute(attr.Name, attr.Value) - } - lastLine.Stop = lastLine.Start + start.Start - node.Lines().Set(lastIndex, lastLine) - } } diff --git a/vendor/github.com/yuin/goldmark/parser/delimiter.go b/vendor/github.com/yuin/goldmark/parser/delimiter.go index 93b32de..be58c2b 100644 --- a/vendor/github.com/yuin/goldmark/parser/delimiter.go +++ b/vendor/github.com/yuin/goldmark/parser/delimiter.go @@ -207,6 +207,7 @@ func ProcessDelimiters(bottom ast.Node, pc Context) { closer.ConsumeCharacters(consume) node := opener.Processor.OnMatch(consume) + node.(interface{ SetPos(int) }).SetPos(opener.Segment.Start) parent := opener.Parent() child := opener.NextSibling() diff --git a/vendor/github.com/yuin/goldmark/parser/fcode_block.go b/vendor/github.com/yuin/goldmark/parser/fcode_block.go index d0833fb..0c265c0 100644 --- a/vendor/github.com/yuin/goldmark/parser/fcode_block.go +++ b/vendor/github.com/yuin/goldmark/parser/fcode_block.go @@ -34,10 +34,7 @@ func (b *fencedCodeBlockParser) Trigger() []byte { func (b *fencedCodeBlockParser) Open(parent ast.Node, reader text.Reader, pc Context) (ast.Node, State) { line, segment := reader.PeekLine() - pos := pc.BlockOffset() - if pos < 0 || (line[pos] != '`' && line[pos] != '~') { - return nil, NoChildren - } + pos := pc.BlockIndent() findent := pos fenceChar := line[pos] i := pos @@ -79,11 +76,7 @@ func (b *fencedCodeBlockParser) Continue(node ast.Node, reader text.Reader, pc C } length := i - pos if length >= fdata.length && util.IsBlank(line[i:]) { - newline := 1 - if line[len(line)-1] != '\n' { - newline = 0 - } - reader.Advance(segment.Stop - segment.Start - newline + segment.Padding) + reader.AdvanceToEOL() return Close } } @@ -99,7 +92,7 @@ func (b *fencedCodeBlockParser) Continue(node ast.Node, reader text.Reader, pc C } seg.ForceNewline = true // EOF as newline node.Lines().Append(seg) - reader.AdvanceAndSetPadding(segment.Stop-segment.Start-pos-1, padding) + reader.AdvanceToEOL() return Continue | NoChildren } diff --git a/vendor/github.com/yuin/goldmark/parser/html_block.go b/vendor/github.com/yuin/goldmark/parser/html_block.go index 262ef93..53e2376 100644 --- a/vendor/github.com/yuin/goldmark/parser/html_block.go +++ b/vendor/github.com/yuin/goldmark/parser/html_block.go @@ -114,9 +114,6 @@ func (b *htmlBlockParser) Open(parent ast.Node, reader text.Reader, pc Context) var node *ast.HTMLBlock line, segment := reader.PeekLine() last := pc.LastOpenedBlock().Node - if pos := pc.BlockOffset(); pos < 0 || line[pos] != '<' { - return nil, NoChildren - } if m := htmlBlockType1OpenRegexp.FindSubmatchIndex(line); m != nil { node = ast.NewHTMLBlock(ast.HTMLBlockType1) diff --git a/vendor/github.com/yuin/goldmark/parser/link.go b/vendor/github.com/yuin/goldmark/parser/link.go index 7390d7b..bd9cf8d 100644 --- a/vendor/github.com/yuin/goldmark/parser/link.go +++ b/vendor/github.com/yuin/goldmark/parser/link.go @@ -166,9 +166,10 @@ func (s *linkParser) Parse(parent ast.Node, block text.Reader, pc Context) ast.N l, pos := block.Position() var link *ast.Link var hasValue bool - if c == '(' { // normal link + switch c { + case '(': link = s.parseLink(parent, last, block, pc) - } else if c == '[' { // reference link + case '[': link, hasValue = s.parseReferenceLink(parent, last, block, pc) if link == nil && hasValue { ast.MergeOrReplaceTextSegment(last.Parent(), last, last.Segment) @@ -200,13 +201,18 @@ func (s *linkParser) Parse(parent ast.Node, block text.Reader, pc Context) ast.N s.processLinkLabel(parent, link, last, pc) link.Title = ref.Title() link.Destination = ref.Destination() + link.Reference = ast.NewReferenceLink(ast.ReferenceLinkShortcut, maybeReference) } + var n ast.Node if last.IsImage { last.Parent().RemoveChild(last.Parent(), last) - return ast.NewImage(link) + n = ast.NewImage(link) + } else { + last.Parent().RemoveChild(last.Parent(), last) + n = link } - last.Parent().RemoveChild(last.Parent(), last) - return link + n.(interface{ SetPos(int) }).SetPos(last.Segment.Start) + return n } func (s *linkParser) containsLink(n ast.Node) bool { @@ -262,11 +268,12 @@ func (s *linkParser) parseReferenceLink(parent ast.Node, last *linkLabelState, } var maybeReference []byte + refType := ast.ReferenceLinkFull if segments.Len() == 1 { // avoid allocate a new byte slice maybeReference = block.Value(segments.At(0)) } else { maybeReference = []byte{} - for i := 0; i < segments.Len(); i++ { + for i := range segments.Len() { s := segments.At(i) maybeReference = append(maybeReference, block.Value(s)...) } @@ -274,6 +281,7 @@ func (s *linkParser) parseReferenceLink(parent ast.Node, last *linkLabelState, if util.IsBlank(maybeReference) { // collapsed reference link s := text.NewSegment(last.Segment.Stop, orgpos.Start-1) maybeReference = block.Value(s) + refType = ast.ReferenceLinkCollapsed } // CommonMark spec says: // > A link label can have at most 999 characters inside the square brackets. @@ -290,6 +298,7 @@ func (s *linkParser) parseReferenceLink(parent ast.Node, last *linkLabelState, s.processLinkLabel(parent, link, last, pc) link.Title = ref.Title() link.Destination = ref.Destination() + link.Reference = ast.NewReferenceLink(refType, maybeReference) return link, true } @@ -388,7 +397,7 @@ func parseLinkTitle(block text.Reader) ([]byte, bool) { return block.Value(segments.At(0)), true } var title []byte - for i := 0; i < segments.Len(); i++ { + for i := range segments.Len() { s := segments.At(i) title = append(title, block.Value(s)...) } diff --git a/vendor/github.com/yuin/goldmark/parser/link_ref.go b/vendor/github.com/yuin/goldmark/parser/link_ref.go index ea3f654..600024a 100644 --- a/vendor/github.com/yuin/goldmark/parser/link_ref.go +++ b/vendor/github.com/yuin/goldmark/parser/link_ref.go @@ -18,8 +18,17 @@ func (p *linkReferenceParagraphTransformer) Transform(node *ast.Paragraph, reade block := text.NewBlockReader(reader.Source(), lines) removes := [][2]int{} for { - start, end := parseLinkReferenceDefinition(block, pc) + ref, start, end := parseLinkReferenceDefinition(block, pc) if start > -1 { + if start == 0 { + ref.SetBlankPreviousLines(node.HasBlankPreviousLines()) + } + node.Parent().InsertBefore(node.Parent(), node, ref) + for i := start + 1; i < end; i++ { + ref.Lines().Append(lines.At(i)) + } + seg := ref.Lines().At(ref.Lines().Len() - 1) + ref.Lines().Set(ref.Lines().Len()-1, seg.TrimRightSpace(reader.Source())) if start == end { end++ } @@ -41,57 +50,56 @@ func (p *linkReferenceParagraphTransformer) Transform(node *ast.Paragraph, reade } if lines.Len() == 0 { - t := ast.NewTextBlock() - t.SetBlankPreviousLines(node.HasBlankPreviousLines()) - node.Parent().ReplaceChild(node.Parent(), node, t) + node.Parent().RemoveChild(node.Parent(), node) return } node.SetLines(lines) } -func parseLinkReferenceDefinition(block text.Reader, pc Context) (int, int) { +func parseLinkReferenceDefinition(block text.Reader, pc Context) (ast.Node, int, int) { block.SkipSpaces() line, _ := block.PeekLine() if line == nil { - return -1, -1 + return nil, -1, -1 } startLine, _ := block.Position() width, pos := util.IndentWidth(line, 0) if width > 3 { - return -1, -1 + return nil, -1, -1 } if width != 0 { pos++ } if line[pos] != '[' { - return -1, -1 + return nil, -1, -1 } + _, startPos := block.Position() block.Advance(pos + 1) segments, found := block.FindClosure('[', ']', linkFindClosureOptions) if !found { - return -1, -1 + return nil, -1, -1 } var label []byte if segments.Len() == 1 { label = block.Value(segments.At(0)) } else { - for i := 0; i < segments.Len(); i++ { + for i := range segments.Len() { s := segments.At(i) label = append(label, block.Value(s)...) } } if util.IsBlank(label) { - return -1, -1 + return nil, -1, -1 } if block.Peek() != ':' { - return -1, -1 + return nil, -1, -1 } block.Advance(1) block.SkipSpaces() destination, ok := parseLinkDestination(block) if !ok { - return -1, -1 + return nil, -1, -1 } line, _ = block.PeekLine() isNewLine := line == nil || util.IsBlank(line) @@ -101,14 +109,15 @@ func parseLinkReferenceDefinition(block text.Reader, pc Context) (int, int) { opener := block.Peek() if opener != '"' && opener != '\'' && opener != '(' { if !isNewLine { - return -1, -1 + return nil, -1, -1 } - ref := NewReference(label, destination, nil) - pc.AddReference(ref) - return startLine, endLine + 1 + ref := ast.NewLinkReferenceDefinition(label, destination, nil) + ref.Lines().Append(startPos) + pc.AddReference(newASTReference(ref)) + return ref, startLine, endLine + 1 } if spaces == 0 { - return -1, -1 + return nil, -1, -1 } block.Advance(1) closer := opener @@ -118,18 +127,19 @@ func parseLinkReferenceDefinition(block text.Reader, pc Context) (int, int) { segments, found = block.FindClosure(opener, closer, linkFindClosureOptions) if !found { if !isNewLine { - return -1, -1 + return nil, -1, -1 } - ref := NewReference(label, destination, nil) - pc.AddReference(ref) + ref := ast.NewLinkReferenceDefinition(label, destination, nil) + ref.Lines().Append(startPos) + pc.AddReference(newASTReference(ref)) block.AdvanceLine() - return startLine, endLine + 1 + return ref, startLine, endLine + 1 } var title []byte if segments.Len() == 1 { title = block.Value(segments.At(0)) } else { - for i := 0; i < segments.Len(); i++ { + for i := range segments.Len() { s := segments.At(i) title = append(title, block.Value(s)...) } @@ -138,15 +148,17 @@ func parseLinkReferenceDefinition(block text.Reader, pc Context) (int, int) { line, _ = block.PeekLine() if line != nil && !util.IsBlank(line) { if !isNewLine { - return -1, -1 + return nil, -1, -1 } - ref := NewReference(label, destination, title) - pc.AddReference(ref) - return startLine, endLine + ref := ast.NewLinkReferenceDefinition(label, destination, title) + ref.Lines().Append(startPos) + pc.AddReference(newASTReference(ref)) + return ref, startLine, endLine } endLine, _ = block.Position() - ref := NewReference(label, destination, title) - pc.AddReference(ref) - return startLine, endLine + 1 + ref := ast.NewLinkReferenceDefinition(label, destination, title) + ref.Lines().Append(startPos) + pc.AddReference(newASTReference(ref)) + return ref, startLine, endLine + 1 } diff --git a/vendor/github.com/yuin/goldmark/parser/list.go b/vendor/github.com/yuin/goldmark/parser/list.go index 3e0eea6..ca7040a 100644 --- a/vendor/github.com/yuin/goldmark/parser/list.go +++ b/vendor/github.com/yuin/goldmark/parser/list.go @@ -18,7 +18,7 @@ const ( var skipListParserKey = NewContextKey() var emptyListItemWithBlankLines = NewContextKey() -var listItemFlagValue interface{} = true +var listItemFlagValue any = true // Same as // `^(([ ]*)([\-\*\+]))(\s+.*)?\n?$`.FindSubmatchIndex or @@ -80,14 +80,6 @@ func parseListItem(line []byte) ([6]int, listItemType) { return ret, typ } -func matchesListItem(source []byte, strict bool) ([6]int, listItemType) { - m, typ := parseListItem(source) - if typ != notList && (!strict || strict && m[1] < 4) { - return m, typ - } - return m, notList -} - func calcListOffset(source []byte, match [6]int) int { var offset int if match[4] < 0 || util.IsBlank(source[match[4]:]) { // list item starts with a blank line @@ -132,7 +124,7 @@ func (b *listParser) Open(parent ast.Node, reader text.Reader, pc Context) (ast. return nil, NoChildren } line, _ := reader.PeekLine() - match, typ := matchesListItem(line, true) + match, typ := parseListItem(line) if typ == notList { return nil, NoChildren } @@ -198,7 +190,7 @@ func (b *listParser) Continue(node ast.Node, reader text.Reader, pc Context) Sta if indent < offset || lastIsEmpty { if indent < 4 { - match, typ := matchesListItem(line, false) // may have a leading spaces more than 3 + match, typ := parseListItem(line) if typ != notList && match[1]-offset < 4 { marker := line[match[3]-1] if !list.CanContinue(marker, typ == orderedList) { diff --git a/vendor/github.com/yuin/goldmark/parser/list_item.go b/vendor/github.com/yuin/goldmark/parser/list_item.go index f4d7da4..9bef62e 100644 --- a/vendor/github.com/yuin/goldmark/parser/list_item.go +++ b/vendor/github.com/yuin/goldmark/parser/list_item.go @@ -28,7 +28,7 @@ func (b *listItemParser) Open(parent ast.Node, reader text.Reader, pc Context) ( } offset := lastOffset(list) line, _ := reader.PeekLine() - match, typ := matchesListItem(line, false) + match, typ := parseListItem(line) if typ == notList { return nil, NoChildren } @@ -61,7 +61,7 @@ func (b *listItemParser) Continue(node ast.Node, reader text.Reader, pc Context) isEmpty := node.ChildCount() == 0 && pc.Get(emptyListItemWithBlankLines) != nil indent, _ := util.IndentWidth(line, reader.LineOffset()) if (isEmpty || indent < offset) && indent < 4 { - _, typ := matchesListItem(line, true) + _, typ := parseListItem(line) // new list item found if typ != notList { pc.Set(skipListParserKey, listItemFlagValue) diff --git a/vendor/github.com/yuin/goldmark/parser/paragraph.go b/vendor/github.com/yuin/goldmark/parser/paragraph.go index 801b0df..ace6042 100644 --- a/vendor/github.com/yuin/goldmark/parser/paragraph.go +++ b/vendor/github.com/yuin/goldmark/parser/paragraph.go @@ -22,9 +22,8 @@ func (b *paragraphParser) Trigger() []byte { } func (b *paragraphParser) Open(parent ast.Node, reader text.Reader, pc Context) (ast.Node, State) { - _, segment := reader.PeekLine() - segment = segment.TrimLeftSpace(reader.Source()) - if segment.IsEmpty() { + line, segment := reader.PeekLine() + if util.IsBlank(line) { return nil, NoChildren } node := ast.NewParagraph() @@ -47,7 +46,7 @@ func (b *paragraphParser) Close(node ast.Node, reader text.Reader, pc Context) { lines := node.Lines() if lines.Len() != 0 { // trim leading spaces - for i := 0; i < lines.Len(); i++ { + for i := range lines.Len() { l := lines.At(i) lines.Set(i, l.TrimLeftSpace(reader.Source())) } diff --git a/vendor/github.com/yuin/goldmark/parser/parser.go b/vendor/github.com/yuin/goldmark/parser/parser.go index 78a6b26..05d5649 100644 --- a/vendor/github.com/yuin/goldmark/parser/parser.go +++ b/vendor/github.com/yuin/goldmark/parser/parser.go @@ -37,6 +37,10 @@ func NewReference(label, destination, title []byte) Reference { return &reference{label, destination, title} } +func newASTReference(v *ast.LinkReferenceDefinition) Reference { + return &astReference{v} +} + func (r *reference) Label() []byte { return r.label } @@ -53,6 +57,26 @@ func (r *reference) String() string { return fmt.Sprintf("Reference{Label:%s, Destination:%s, Title:%s}", r.label, r.destination, r.title) } +type astReference struct { + v *ast.LinkReferenceDefinition +} + +func (r *astReference) Label() []byte { + return r.v.Label +} + +func (r *astReference) Destination() []byte { + return r.v.Destination +} + +func (r *astReference) Title() []byte { + return r.v.Title +} + +func (r *astReference) String() string { + return fmt.Sprintf("Reference{Label:%s, Destination:%s, Title:%s}", r.Label(), r.Destination(), r.Title()) +} + // An IDs interface is a collection of the element ids. type IDs interface { // Generate generates a new element id. @@ -136,13 +160,13 @@ type Context interface { String() string // Get returns a value associated with the given key. - Get(ContextKey) interface{} + Get(ContextKey) any // ComputeIfAbsent computes a value if a value associated with the given key is absent and returns the value. - ComputeIfAbsent(ContextKey, func() interface{}) interface{} + ComputeIfAbsent(ContextKey, func() any) any // Set sets the given value to the context. - Set(ContextKey, interface{}) + Set(ContextKey, any) // AddReference adds the given reference to this context. AddReference(Reference) @@ -220,7 +244,7 @@ func WithIDs(ids IDs) ContextOption { } type parseContext struct { - store []interface{} + store []any ids IDs refs map[string]Reference blockOffset int @@ -240,7 +264,7 @@ func NewContext(options ...ContextOption) Context { } return &parseContext{ - store: make([]interface{}, ContextKeyMax+1), + store: make([]any, ContextKeyMax+1), refs: map[string]Reference{}, ids: cfg.IDs, blockOffset: -1, @@ -251,11 +275,11 @@ func NewContext(options ...ContextOption) Context { } } -func (p *parseContext) Get(key ContextKey) interface{} { +func (p *parseContext) Get(key ContextKey) any { return p.store[key] } -func (p *parseContext) ComputeIfAbsent(key ContextKey, f func() interface{}) interface{} { +func (p *parseContext) ComputeIfAbsent(key ContextKey, f func() any) any { v := p.store[key] if v == nil { v = f() @@ -264,7 +288,7 @@ func (p *parseContext) ComputeIfAbsent(key ContextKey, f func() interface{}) int return v } -func (p *parseContext) Set(key ContextKey, value interface{}) { +func (p *parseContext) Set(key ContextKey, value any) { p.store[key] = value } @@ -426,7 +450,7 @@ const ( // A Config struct is a data structure that holds configuration of the Parser. type Config struct { - Options map[OptionName]interface{} + Options map[OptionName]any BlockParsers util.PrioritizedSlice /**/ InlineParsers util.PrioritizedSlice /**/ ParagraphTransformers util.PrioritizedSlice /**/ @@ -437,7 +461,7 @@ type Config struct { // NewConfig returns a new Config. func NewConfig() *Config { return &Config{ - Options: map[OptionName]interface{}{}, + Options: map[OptionName]any{}, BlockParsers: util.PrioritizedSlice{}, InlineParsers: util.PrioritizedSlice{}, ParagraphTransformers: util.PrioritizedSlice{}, @@ -482,7 +506,7 @@ type SetOptioner interface { // SetOption sets the given option to the object. // Unacceptable options may be passed. // Thus implementations must ignore unacceptable options. - SetOption(name OptionName, value interface{}) + SetOption(name OptionName, value any) } // A BlockParser interface parses a block level element like Paragraph, List, @@ -630,7 +654,7 @@ type Block struct { } type parser struct { - options map[OptionName]interface{} + options map[OptionName]any blockParsers [256][]BlockParser freeBlockParsers []BlockParser inlineParsers [256][]InlineParser @@ -712,7 +736,7 @@ func WithEscapedSpace() Option { type withOption struct { name OptionName - value interface{} + value any } func (o *withOption) SetParserOption(c *Config) { @@ -721,7 +745,7 @@ func (o *withOption) SetParserOption(c *Config) { // WithOption is a functional option that allow you to set // an arbitrary option to the parser. -func WithOption(name OptionName, value interface{}) Option { +func WithOption(name OptionName, value any) Option { return &withOption{name, value} } @@ -733,7 +757,7 @@ func NewParser(options ...Option) Parser { } p := &parser{ - options: map[OptionName]interface{}{}, + options: map[OptionName]any{}, config: config, } @@ -746,7 +770,7 @@ func (p *parser) AddOptions(opts ...Option) { } } -func (p *parser) addBlockParser(v util.PrioritizedValue, options map[OptionName]interface{}) { +func (p *parser) addBlockParser(v util.PrioritizedValue, options map[OptionName]any) { bp, ok := v.Value.(BlockParser) if !ok { panic(fmt.Sprintf("%v is not a BlockParser", v.Value)) @@ -770,7 +794,7 @@ func (p *parser) addBlockParser(v util.PrioritizedValue, options map[OptionName] } } -func (p *parser) addInlineParser(v util.PrioritizedValue, options map[OptionName]interface{}) { +func (p *parser) addInlineParser(v util.PrioritizedValue, options map[OptionName]any) { ip, ok := v.Value.(InlineParser) if !ok { panic(fmt.Sprintf("%v is not a InlineParser", v.Value)) @@ -793,7 +817,7 @@ func (p *parser) addInlineParser(v util.PrioritizedValue, options map[OptionName } } -func (p *parser) addParagraphTransformer(v util.PrioritizedValue, options map[OptionName]interface{}) { +func (p *parser) addParagraphTransformer(v util.PrioritizedValue, options map[OptionName]any) { pt, ok := v.Value.(ParagraphTransformer) if !ok { panic(fmt.Sprintf("%v is not a ParagraphTransformer", v.Value)) @@ -807,7 +831,7 @@ func (p *parser) addParagraphTransformer(v util.PrioritizedValue, options map[Op p.paragraphTransformers = append(p.paragraphTransformers, pt) } -func (p *parser) addASTTransformer(v util.PrioritizedValue, options map[OptionName]interface{}) { +func (p *parser) addASTTransformer(v util.PrioritizedValue, options map[OptionName]any) { at, ok := v.Value.(ASTTransformer) if !ok { panic(fmt.Sprintf("%v is not a ASTTransformer", v.Value)) @@ -961,13 +985,17 @@ retry: if continuable && result == noBlocksOpened && !bp.CanInterruptParagraph() { continue } + if w > 3 && !bp.CanAcceptIndentedLine() { continue } lastBlock = pc.LastOpenedBlock() last := lastBlock.Node + _, blockPos := reader.Position() node, state := bp.Open(parent, reader, pc) if node != nil { + node.SetPos(blockPos.Start + max(pc.BlockOffset(), 0)) + // Parser requires last node to be a paragraph. // With table extension: // @@ -1066,7 +1094,7 @@ func (p *parser) parseBlocks(parent ast.Node, reader text.Reader, pc Context) { break } lastIndex := l - 1 - for i := 0; i < l; i++ { + for i := range l { be := openedBlocks[i] line, _ := reader.PeekLine() if line == nil { @@ -1170,7 +1198,7 @@ func (p *parser) parseBlock(block text.BlockReader, parent ast.Node, pc Context) l, startPosition := block.Position() n := 0 - for i := 0; i < lineLength; i++ { + for i := range lineLength { c := line[i] if c == '\n' { break @@ -1196,6 +1224,9 @@ func (p *parser) parseBlock(block text.BlockReader, parent ast.Node, pc Context) for _, ip := range ips { inlineNode = ip.Parse(parent, block, pc) if inlineNode != nil { + if inlineNode.Pos() < 0 { + inlineNode.(interface{ SetPos(int) }).SetPos(startPosition.Start) + } break } block.SetPosition(savedLine, savedPosition) diff --git a/vendor/github.com/yuin/goldmark/parser/raw_html.go b/vendor/github.com/yuin/goldmark/parser/raw_html.go index 1d582a7..a374614 100644 --- a/vendor/github.com/yuin/goldmark/parser/raw_html.go +++ b/vendor/github.com/yuin/goldmark/parser/raw_html.go @@ -63,7 +63,7 @@ var emptyComment2 = []byte("") var openComment = []byte("") -func (s *rawHTMLParser) parseComment(block text.Reader, pc Context) ast.Node { +func (s *rawHTMLParser) parseComment(block text.Reader, _ Context) ast.Node { savedLine, savedSegment := block.Position() node := ast.NewRawHTML() line, segment := block.PeekLine() @@ -98,7 +98,7 @@ func (s *rawHTMLParser) parseComment(block text.Reader, pc Context) ast.Node { return nil } -func (s *rawHTMLParser) parseUntil(block text.Reader, closer []byte, pc Context) ast.Node { +func (s *rawHTMLParser) parseUntil(block text.Reader, closer []byte, _ Context) ast.Node { savedLine, savedSegment := block.Position() node := ast.NewRawHTML() for { @@ -119,7 +119,7 @@ func (s *rawHTMLParser) parseUntil(block text.Reader, closer []byte, pc Context) return nil } -func (s *rawHTMLParser) parseMultiLineRegexp(reg *regexp.Regexp, block text.Reader, pc Context) ast.Node { +func (s *rawHTMLParser) parseMultiLineRegexp(reg *regexp.Regexp, block text.Reader, _ Context) ast.Node { sline, ssegment := block.Position() if block.Match(reg) { node := ast.NewRawHTML() diff --git a/vendor/github.com/yuin/goldmark/parser/setext_headings.go b/vendor/github.com/yuin/goldmark/parser/setext_headings.go index 915bcc1..3558baa 100644 --- a/vendor/github.com/yuin/goldmark/parser/setext_headings.go +++ b/vendor/github.com/yuin/goldmark/parser/setext_headings.go @@ -95,6 +95,7 @@ func (b *setextHeadingParser) Close(node ast.Node, reader text.Reader, pc Contex } heading.Parent().RemoveChild(heading.Parent(), heading) } else { + heading.SetPos(tmp.Lines().At(0).Start) heading.SetLines(tmp.Lines()) heading.SetBlankPreviousLines(tmp.HasBlankPreviousLines()) tp := tmp.Parent() diff --git a/vendor/github.com/yuin/goldmark/renderer/html/html.go b/vendor/github.com/yuin/goldmark/renderer/html/html.go index 903dc68..c0b72ce 100644 --- a/vendor/github.com/yuin/goldmark/renderer/html/html.go +++ b/vendor/github.com/yuin/goldmark/renderer/html/html.go @@ -34,7 +34,7 @@ func NewConfig() Config { } // SetOption implements renderer.NodeRenderer.SetOption. -func (c *Config) SetOption(name renderer.OptionName, value interface{}) { +func (c *Config) SetOption(name renderer.OptionName, value any) { switch name { case optHardWraps: c.HardWraps = value.(bool) @@ -273,6 +273,10 @@ func (r *Renderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) { reg.Register(ast.KindParagraph, r.renderParagraph) reg.Register(ast.KindTextBlock, r.renderTextBlock) reg.Register(ast.KindThematicBreak, r.renderThematicBreak) + reg.Register(ast.KindLinkReferenceDefinition, func( + _ util.BufWriter, _ []byte, _ ast.Node, _ bool) (ast.WalkStatus, error) { + return ast.WalkSkipChildren, nil + }) // inlines @@ -288,7 +292,7 @@ func (r *Renderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) { func (r *Renderer) writeLines(w util.BufWriter, source []byte, n ast.Node) { l := n.Lines().Len() - for i := 0; i < l; i++ { + for i := range l { line := n.Lines().At(i) r.Writer.RawWrite(w, line.Value(source)) } @@ -378,7 +382,7 @@ func (r *Renderer) renderHTMLBlock( if entering { if r.Unsafe { l := n.Lines().Len() - for i := 0; i < l; i++ { + for i := range l { line := n.Lines().At(i) r.Writer.SecureWrite(w, line.Value(source)) } @@ -497,7 +501,7 @@ func (r *Renderer) renderThematicBreak( } // LinkAttributeFilter defines attribute names which link elements can have. -var LinkAttributeFilter = GlobalAttributeFilter.ExtendString(`download,hreflang,media,ping,referrerpolicy,rel,shape,target`) // nolint:lll +var LinkAttributeFilter = GlobalAttributeFilter.ExtendString(`download,href,lang,media,ping,referrerpolicy,rel,shape,target`) // nolint:lll func (r *Renderer) renderAutoLink( w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { @@ -506,12 +510,14 @@ func (r *Renderer) renderAutoLink( return ast.WalkContinue, nil } _, _ = w.WriteString(`= width { @@ -225,13 +228,15 @@ func DedentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, pad w := 0 i := 0 l := len(bs) +loop: for ; i < l; i++ { - if bs[i] == '\t' { + switch bs[i] { + case '\t': w += TabWidth(currentPos + w) - } else if bs[i] == ' ' { + case ' ': w++ - } else { - break + default: + break loop } } if w >= width { @@ -242,17 +247,16 @@ func DedentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, pad // IndentWidth calculate an indent width for the given line. func IndentWidth(bs []byte, currentPos int) (width, pos int) { - l := len(bs) - for i := 0; i < l; i++ { - b := bs[i] - if b == ' ' { + for i := range len(bs) { + switch bs[i] { + case ' ': width++ pos++ - } else if b == '\t' { + case '\t': width += TabWidth(currentPos + width) pos++ - } else { - break + default: + return } } return @@ -315,12 +319,13 @@ func FindClosure(bs []byte, opener, closure byte, codeSpan, allowNesting bool) i } } } else if (codeSpan && codeSpanOpener == 0) || !codeSpan { - if c == closure { + switch c { + case closure: opened-- if opened == 0 { return i } - } else if c == opener { + case opener: if !allowNesting { return -1 } @@ -340,7 +345,7 @@ func TrimLeft(source, b []byte) []byte { for ; i < len(source); i++ { c := source[i] found := false - for j := 0; j < len(b); j++ { + for j := range len(b) { if c == b[j] { found = true break @@ -359,7 +364,7 @@ func TrimRight(source, b []byte) []byte { for ; i >= 0; i-- { c := source[i] found := false - for j := 0; j < len(b); j++ { + for j := range len(b) { if c == b[j] { found = true break @@ -532,8 +537,9 @@ var htmlQuote = []byte(""") var htmlAmp = []byte("&") var htmlLess = []byte("<") var htmlGreater = []byte(">") +var htmlNull = []byte("\ufffd") -var htmlEscapeTable = [256]*[]byte{nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, &htmlQuote, nil, nil, nil, &htmlAmp, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, &htmlLess, nil, &htmlGreater, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} //nolint:golint,lll +var htmlEscapeTable = [256]*[]byte{&htmlNull, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, &htmlQuote, nil, nil, nil, &htmlAmp, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, &htmlLess, nil, &htmlGreater, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} //nolint:golint,lll // EscapeHTMLByte returns HTML escaped bytes if the given byte should be escaped, // otherwise nil. @@ -549,7 +555,7 @@ func EscapeHTMLByte(b byte) []byte { func EscapeHTML(v []byte) []byte { cob := NewCopyOnWriteBuffer(v) n := 0 - for i := 0; i < len(v); i++ { + for i := range len(v) { c := v[i] escaped := htmlEscapeTable[c] if escaped != nil { @@ -865,7 +871,7 @@ type BufWriter interface { // A PrioritizedValue struct holds pair of an arbitrary value and a priority. type PrioritizedValue struct { // Value is an arbitrary value that you want to prioritize. - Value interface{} + Value any // Priority is a priority of the value. Priority int } @@ -881,7 +887,7 @@ func (s PrioritizedSlice) Sort() { } // Remove removes the given value from this slice. -func (s PrioritizedSlice) Remove(v interface{}) PrioritizedSlice { +func (s PrioritizedSlice) Remove(v any) PrioritizedSlice { i := 0 found := false for ; i < len(s); i++ { @@ -893,11 +899,11 @@ func (s PrioritizedSlice) Remove(v interface{}) PrioritizedSlice { if !found { return s } - return append(s[:i], s[i+1:]...) + return slices.Delete(s, i, i+1) } // Prioritized returns a new PrioritizedValue. -func Prioritized(v interface{}, priority int) PrioritizedValue { +func Prioritized(v any, priority int) PrioritizedValue { return PrioritizedValue{v, priority} } @@ -952,7 +958,7 @@ func NewBytesFilterString(elements string) BytesFilter { slots: make([][][]byte, 64), } start := 0 - for i := 0; i < len(elements); i++ { + for i := range len(elements) { if elements[i] == ',' { s.Add(StringToReadOnlyBytes(elements[start:i])) start = i + 1 @@ -967,11 +973,8 @@ func NewBytesFilterString(elements string) BytesFilter { func (s *bytesFilter) Add(b []byte) { l := len(b) - m := s.threshold - if l < s.threshold { - m = l - } - for i := 0; i < m; i++ { + m := min(l, s.threshold) + for i := range m { s.chars[b[i]] |= 1 << uint8(i) } h := bytesHash(b) % uint64(len(s.slots)) @@ -1007,7 +1010,7 @@ func (s *bytesFilter) ExtendString(elements string) BytesFilter { newFilter.slots[k] = v } start := 0 - for i := 0; i < len(elements); i++ { + for i := range len(elements) { if elements[i] == ',' { newFilter.Add(StringToReadOnlyBytes(elements[start:i])) start = i + 1 @@ -1021,11 +1024,8 @@ func (s *bytesFilter) ExtendString(elements string) BytesFilter { func (s *bytesFilter) Contains(b []byte) bool { l := len(b) - m := s.threshold - if l < s.threshold { - m = l - } - for i := 0; i < m; i++ { + m := min(l, s.threshold) + for i := range m { if (s.chars[b[i]] & (1 << uint8(i))) == 0 { return false } -- cgit v1.3.1