goldmark-highlighting
goldmark-highlighting copied to clipboard
Update chroma to v2
This updates chroma
to v2.
For context on the below comments, previously this used a version prior to a breaking change.
@zeripath was gracious enough to send a patch that allows the latest version of chroma
.
Heya @jolheiser how about doing this?
From 50ca7b0882b7c1beadb158f5fa6718db266dad58 Mon Sep 17 00:00:00 2001
From: Andrew Thornton <[email protected]>
Date: Tue, 26 Jul 2022 19:37:22 +0100
Subject: [PATCH] Upgrade to Chroma 2.2.0
Adjust the tests to account for the change PreventSurroundingPre()
---
go.mod | 3 ++-
go.sum | 7 ++++---
highlighting_test.go | 10 +++++++++-
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/go.mod b/go.mod
index cd7124a..036deb2 100644
--- a/go.mod
+++ b/go.mod
@@ -3,6 +3,7 @@ module github.com/yuin/goldmark-highlighting
go 1.13
require (
- github.com/alecthomas/chroma/v2 v2.1.0
+ github.com/alecthomas/chroma/v2 v2.2.0
+ github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/yuin/goldmark v1.4.5
)
diff --git a/go.sum b/go.sum
index 225e6af..4584097 100644
--- a/go.sum
+++ b/go.sum
@@ -1,12 +1,13 @@
-github.com/alecthomas/chroma/v2 v2.1.0 h1:ZG9L5/RsxO/xIONrBy8Cgo+5si3d9x3osweXc4VHl0o=
-github.com/alecthomas/chroma/v2 v2.1.0/go.mod h1:vf4zrexSH54oEjJ7EdB65tGNHmH3pGZmVkgTP5RHvAs=
+github.com/alecthomas/chroma/v2 v2.2.0 h1:Aten8jfQwUqEdadVFFjNyjx7HTexhKP0XuqBG67mRDY=
+github.com/alecthomas/chroma/v2 v2.2.0/go.mod h1:vf4zrexSH54oEjJ7EdB65tGNHmH3pGZmVkgTP5RHvAs=
github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae h1:zzGwJfFlFGD94CyyYwCJeSuD32Gj9GTaSi5y9hoVzdY=
github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
+github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
+github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
diff --git a/highlighting_test.go b/highlighting_test.go
index 9eb9a98..1b8e96e 100644
--- a/highlighting_test.go
+++ b/highlighting_test.go
@@ -428,6 +428,14 @@ LINE8
}
}
+type nopPreWrapper struct{}
+
+// Start is called to write a start <pre> element.
+func (nopPreWrapper) Start(code bool, styleAttr string) string { return "" }
+
+// End is called to write the end </pre> element.
+func (nopPreWrapper) End(code bool) string { return "" }
+
func TestHighlightingLinenos(t *testing.T) {
outputLineNumbersInTable := `<div class="chroma">
<table class="lntable"><tr><td class="lntd">
@@ -464,7 +472,7 @@ func TestHighlightingLinenos(t *testing.T) {
WithFormatOptions(
chromahtml.WithLineNumbers(test.lineNumbers),
chromahtml.LineNumbersInTable(test.lineNumbersInTable),
- chromahtml.PreventSurroundingPre(true),
+ chromahtml.WithPreWrapper(nopPreWrapper{}),
chromahtml.WithClasses(true),
),
),
--
2.37.1
@zeripath Thanks for the patch! I've applied it, so now this is using the latest version of chroma
.
CC @yuin
This PR breaks goldmark-highlighting compatibility as well. So This should be v2.
This PR breaks goldmark-highlighting compatibility as well. So This should be v2.
Fine with me. Do you want me to mark this go.mod
as v2
? Do you want to make a v2
branch, or make master
point to v2
and have a separate v1
branch?
@jolheiser Sorry for late reply. I've pushed the v2 branch into this repository. Could you rebase your branch and change PR target branch to the v2.
- TODO
- merge your PR
- update README for v1 and v2
- change the default branch to v2
@yuin I've rebased onto v2
and updated. (It appears I mucked the commit messages a bit, but should be fine)
@jolheiser I've updated READMEs and made v2 a default branch. Thanks for your contribution.