From 3b28429a3726d03c09dc6d7d16f32adffd65a1b4 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Fri, 16 Oct 2026 00:13:26 -0400 Subject: [PATCH] build(deps): migrate to goldmark v2 --- go.mod | 6 +++--- go.sum | 12 +++++------ internal/markdown/renderer.go | 29 +++++++++++++------------- internal/ui/chat/composer/model.go | 9 ++++---- internal/ui/chat/messageslist/model.go | 8 +++---- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/go.mod b/go.mod index acb47dc..a198a3f 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ replace github.com/bogdanfinn/fhttp => github.com/ayn2op/fhttp v0.6.10-0.2026101 require ( github.com/BurntSushi/toml v1.6.0 github.com/alecthomas/chroma/v2 v2.27.0 - github.com/ayn2op/arikawa/v3 v3.0.0-20261014035141-32b58d8f3755 + github.com/ayn2op/arikawa/v3 v3.0.0-20261016043052-54a68a54e42e github.com/ayn2op/ningen/v3 v3.0.1-0.20261014035153-5e43590a1426 github.com/ayn2op/tview v0.0.0-20261015233535-ab884c65f4fe github.com/bogdanfinn/fhttp v0.6.9 @@ -30,7 +30,7 @@ require ( github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 github.com/thomas-vilte/dave-go v0.5.1 github.com/tphakala/go-opus v1.2.1 - github.com/yuin/goldmark v1.8.6 + github.com/yuin/goldmark/v2 v2.1.6 github.com/zalando/go-keyring v0.2.8 golang.design/x/clipboard v0.11.0 golang.org/x/image v0.47.0 @@ -50,7 +50,7 @@ require ( github.com/danieljoos/wincred v1.2.3 // indirect github.com/dchest/jsmin v1.0.0 // indirect github.com/disgoorg/godave v0.3.0 // indirect - github.com/dlclark/regexp2/v2 v2.8.4 // indirect + github.com/dlclark/regexp2/v2 v2.9.0 // indirect github.com/ebitengine/purego v0.11.1 // indirect github.com/gdamore/encoding v1.0.1 // indirect github.com/godbus/dbus/v5 v5.2.4 // indirect diff --git a/go.sum b/go.sum index 438cc7c..4293182 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/andybalholm/brotli v1.2.6 h1:ftYnfj6usCp+UGV5kSJ3+chpMQgU+gJf/AxsUQ52REI= github.com/andybalholm/brotli v1.2.6/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= -github.com/ayn2op/arikawa/v3 v3.0.0-20261014035141-32b58d8f3755 h1:XHo9kizImaAEtJJky4GZOBTalze42GIVDViqirjuPBY= -github.com/ayn2op/arikawa/v3 v3.0.0-20261014035141-32b58d8f3755/go.mod h1:YARcqZmk7hDjXB+lexlXX4wDFHULafbGnF0gsD0tuNw= +github.com/ayn2op/arikawa/v3 v3.0.0-20261016043052-54a68a54e42e h1:jYi14tMaIrOr8/IydOmHcpEWz4keWH8zJoK8eKYF/lI= +github.com/ayn2op/arikawa/v3 v3.0.0-20261016043052-54a68a54e42e/go.mod h1:h2k8uDqPkJ8oQmBe5brLwuBaJWMSglq9sZ5B1TjmTdo= github.com/ayn2op/fhttp v0.6.10-0.20261016015330-2d5e34c6b935 h1:oVxkY1/nVsVQ8Cn/hxJckflbBEUkd5PBLOELAeAhGLA= github.com/ayn2op/fhttp v0.6.10-0.20261016015330-2d5e34c6b935/go.mod h1:7phoj3f/q54WuiTnCTlAhEoaVcdlruKkSzCSD47LzHk= github.com/ayn2op/ningen/v3 v3.0.1-0.20261014035153-5e43590a1426 h1:0ndRWpAiSSgR0z9b7K+pwMlCHEk3VzQeS5ls+zWtbr0= @@ -42,8 +42,8 @@ github.com/dchest/jsmin v1.0.0 h1:Y2hWXmGZiRxtl+VcTksyucgTlYxnhPzTozCwx9gy9zI= github.com/dchest/jsmin v1.0.0/go.mod h1:AVBIund7Mr7lKXT70hKT2YgL3XEXUaUk5iw9DZ8b0Uc= github.com/disgoorg/godave v0.3.0 h1:37F3ZuiMd8/EXeoCtTeE8iP2eT2nWsfEa4/ITwoKfe4= github.com/disgoorg/godave v0.3.0/go.mod h1:OreAC3hpabr39bMVA+jwOVDq1EUPXH5A0XUBiZaDI1Y= -github.com/dlclark/regexp2/v2 v2.8.4 h1:yfDDXTn4oxyLDC10/ieOBNDCCdIVWS9WbT6ddVXsPKI= -github.com/dlclark/regexp2/v2 v2.8.4/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= +github.com/dlclark/regexp2/v2 v2.9.0 h1:kKj+BlRuUhZzJk8B3yOBxWKxDFnx2Ilq4e7KNdq/Mxk= +github.com/dlclark/regexp2/v2 v2.9.0/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= github.com/ebitengine/purego v0.11.1 h1:2zpWRSQNVKN4eKsKO9eM1ILDgWfYMY9GwqRmK6XeQ/0= github.com/ebitengine/purego v0.11.1/go.mod h1:DCHPP08djqhNSoTfImcnHYQRZmd0qhakvrozqaEYhGQ= github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw= @@ -103,8 +103,8 @@ github.com/twmb/murmur3 v1.2.1/go.mod h1:LVqs/avIy0flspVtmBd4VSbogDepFl6Wkj0i0To github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU= github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/yuin/goldmark v1.8.6 h1:d0VcaP1sx9GkFVkoW+KtggpGi2KZ965i14b0+bDQST4= -github.com/yuin/goldmark v1.8.6/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg= +github.com/yuin/goldmark/v2 v2.1.6 h1:igy0q9JcqovoFXFx/XjtU8sHVhcUHavPj2sA3EoKJUE= +github.com/yuin/goldmark/v2 v2.1.6/go.mod h1:G6M4/qOFtfn01/o14BU1UR2Lo5N3S9Qo7xCuz/sHjGQ= github.com/zalando/go-keyring v0.2.8 h1:6sD/Ucpl7jNq10rM2pgqTs0sZ9V3qMrqfIIy5YPccHs= github.com/zalando/go-keyring v0.2.8/go.mod h1:tsMo+VpRq5NGyKfxoBVjCuMrG47yj8cmakZDO5QGii0= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= diff --git a/internal/markdown/renderer.go b/internal/markdown/renderer.go index 2d907c3..410d510 100644 --- a/internal/markdown/renderer.go +++ b/internal/markdown/renderer.go @@ -12,7 +12,7 @@ import ( "github.com/ayn2op/tview" "github.com/ayn2op/tview/richtext" "github.com/gdamore/tcell/v3" - "github.com/yuin/goldmark/ast" + "github.com/yuin/goldmark/v2/ast" ) type Renderer struct { @@ -61,7 +61,7 @@ func (r *Renderer) RenderText(source []byte, node ast.Node, base tview.Style) ri } case *ast.Text: if entering { - builder.Write(string(node.Segment.Value(source)), currentStyle()) + builder.Write(string(node.Value.Bytes(source)), currentStyle()) switch { case node.HardLineBreak(): builder.NewLine() @@ -70,20 +70,20 @@ func (r *Renderer) RenderText(source []byte, node ast.Node, base tview.Style) ri builder.NewLine() } } - case *ast.FencedCodeBlock: + case *ast.CodeBlock: if entering { builder.NewLine() - r.renderFencedCodeBlock(builder, source, node, currentStyle()) + r.renderCodeBlock(builder, source, node, currentStyle()) } case *ast.AutoLink: if entering { - url := string(node.URL(source)) + url := string(node.Destination.Bytes(source)) style := tview.MergeStyle(currentStyle(), theme.URLStyle.Style).Url(url) builder.Write(url, style) } case *ast.Link: if entering { - url := string(node.Destination) + url := string(node.Destination.Bytes(source)) linkDepth++ pushStyle(tview.MergeStyle(currentStyle(), theme.URLStyle.Style).Url(url)) } else { @@ -145,15 +145,15 @@ func (r *Renderer) RenderText(source []byte, node ast.Node, base tview.Style) ri return builder.Finish() } -func (r *Renderer) renderFencedCodeBlock(builder *richtext.Builder, source []byte, node *ast.FencedCodeBlock, base tview.Style) { +func (r *Renderer) renderCodeBlock(builder *richtext.Builder, source []byte, node *ast.CodeBlock, base tview.Style) { var code strings.Builder - lines := node.Lines() - for i := range lines.Len() { - line := lines.At(i) - code.Write(line.Value(source)) + lines := node.Value.Segments() + for _, line := range lines { + code.Write(line.Bytes(source)) } - language := strings.TrimSpace(string(node.Language(source))) + language, _ := node.Language(source) + language = strings.TrimSpace(language) lexer := lexers.Get(language) declaredLanguageSupported := lexer != nil @@ -186,9 +186,8 @@ func (r *Renderer) renderFencedCodeBlock(builder *richtext.Builder, source []byt iterator, err := lexer.Tokenise(nil, code.String()) if err != nil { - for i := range lines.Len() { - line := lines.At(i) - builder.Write(codeBlockIndent+string(line.Value(source)), base) + for _, line := range lines { + builder.Write(codeBlockIndent+string(line.Bytes(source)), base) } return } diff --git a/internal/ui/chat/composer/model.go b/internal/ui/chat/composer/model.go index b042719..74e552e 100644 --- a/internal/ui/chat/composer/model.go +++ b/internal/ui/chat/composer/model.go @@ -32,7 +32,7 @@ import ( "github.com/ayn2op/tview/textarea" "github.com/gdamore/tcell/v3" "github.com/rivo/uniseg" - "github.com/yuin/goldmark/ast" + "github.com/yuin/goldmark/v2/ast" "golang.design/x/clipboard" ) @@ -363,15 +363,16 @@ func (m Model) processText(channel *discord.Channel, src []byte) string { _ = ast.Walk(md.Parse(src), func(node ast.Node, enter bool) (ast.WalkStatus, error) { switch node := node.(type) { - case *ast.CodeBlock, *ast.FencedCodeBlock: + case *ast.CodeBlock: canMention = !enter case *md.Inline: if (node.Attr & md.AttrMonospace) != 0 { canMention = !enter } case *ast.Text: - if enter && canMention { - ranges = append(ranges, [2]int{node.Segment.Start, node.Segment.Stop}) + if enter && canMention && !node.Value.IsOwned() { + index := node.Value.Index() + ranges = append(ranges, [2]int{index.Start, index.Stop}) } } return ast.WalkContinue, nil diff --git a/internal/ui/chat/messageslist/model.go b/internal/ui/chat/messageslist/model.go index 977a989..69a01ae 100644 --- a/internal/ui/chat/messageslist/model.go +++ b/internal/ui/chat/messageslist/model.go @@ -43,7 +43,7 @@ import ( "github.com/gdamore/tcell/v3" "github.com/gdamore/tcell/v3/color" "github.com/rivo/uniseg" - "github.com/yuin/goldmark/ast" + "github.com/yuin/goldmark/v2/ast" ) type messageItem struct { @@ -614,7 +614,7 @@ func (m Model) drawContent(builder *richtext.Builder, message discord.Message, b startsWithCodeBlock := false if root != nil { if first := root.FirstChild(); first != nil { - _, startsWithCodeBlock = first.(*ast.FencedCodeBlock) + _, startsWithCodeBlock = first.(*ast.CodeBlock) } } @@ -1239,9 +1239,9 @@ func urlsFromAST(node ast.Node, src []byte) []string { if entering { switch n := n.(type) { case *ast.AutoLink: - urls = append(urls, string(n.URL(src))) + urls = append(urls, string(n.Destination.Bytes(src))) case *ast.Link: - urls = append(urls, string(n.Destination)) + urls = append(urls, string(n.Destination.Bytes(src))) } }