depado / bfchroma Goto Github PK
View Code? Open in Web Editor NEWIntegrating Chroma syntax highlighter as a Blackfriday renderer
License: MIT License
Integrating Chroma syntax highlighter as a Blackfriday renderer
License: MIT License
this package listed in go.mod does not exist: github.com/russross/blackfriday/v2
couldn't support utf-8 code. Chinese font.
Hi, I am having trouble writing tests when using this library.
The following test always fails:
import (
"bufio"
"fmt"
"github.com/Depado/bfchroma"
"github.com/renatoathaydes/magnanimous/mg"
"gopkg.in/russross/blackfriday.v2"
"strings"
"testing"
)
func TestBfChroma(t *testing.T) {
var chromaRenderer = blackfriday.WithRenderer(bfchroma.NewRenderer(bfchroma.WithoutAutodetect()))
examples := []string{
"# hello\n## world",
"# hello\n## world",
}
expectedResult := "\n<h1>hello</h1>\n\n<h2>world</h2>\n"
for i, v := range examples {
r := blackfriday.Run([]byte(v), chromaRenderer)
if string(r) != expectedResult {
t.Errorf("[%d] '%s' != %s", i, string(r), expectedResult)
} else {
fmt.Printf("[%d] All good\n", i)
}
}
}
The first iteration results in text that does NOT contain a trailing new-line, but the second (and further) iterations do.
This is undeterministic in the sense that the same input does not always result in the same output. This causes havoc on testing as depending on the order tests run, I get different results.
Finally, I don't think the trailing new-line was supposed to be there anyway. Using just blackfriday
, it consistently gives the same output, without the trailing new-line.
Hi Depado. Thanks for building this package!
A couple comments from me:
Can you provide a constructor that picks some sane defaults for the fallback renderer and the color scheme? It would be super neat if using Blackfriday+bfchrome were as easy as this:
html := bf.Run([]byte(md), bf.WithRenderer(bfchroma.NewRenderer()))
There are several options for providing both easy defaults and customization: you can have several
constructors, an Options
struct or the functional options approach. Pick any of them
and make bfchroma extensible.
In addition to that, please export the renderWithChroma
function for people who might want to use your basic functionality, but incorporate it into a larger renderer of their own.
The following section seems to not be highlighted as YAML, and I'm not sure why not (ignore the backslashes; I had to "escape" the code fences or it breaks github rendering--GH doesn't support nested code fences afaict):
\`\`\`yaml
pipelines:
default:
- step:
services:
- docker
caches:
- docker
script:
- docker build -t weberc2/neon:latest .
- docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD
- docker tag weberc2/neon weberc2/neon:$BITBUCKET_COMMIT
- docker push weberc2/neon:latest
- docker push weberc2/neon:$BITBUCKET_COMMIT
\`\`\`
I assume it's user error, but I'm not really sure how to set about debugging.
I'm getting an error while using go mod with an import declaration for bfchroma
From what I can tell go.mod file contains the line
require "github.com/russross/blackfriday v2.0.0+incompatible
this is obvious not version 2.0.1. I don't understand what's wrong exactly. If this is a blackfriday issue, I will gladly take it up with them. Figured I'd start here since this is the package that is causing the error.
2019/06/17 12:21:53 ERROR โถ 0066 Failed to build the application: go: downloading gopkg.in/russross/blackfriday.v2 v2.0.1 go: gopkg.in/russross/[email protected]: go.mod has non-....v2 module path "github.com/russross/blackfriday/v2" at revision v2.0.1
I am trying to use this module with a Go 1.11 module.
I have this in my go.mod
file:
require (
github.com/Depado/bfchroma v1.1.1
github.com/russross/blackfriday v2.0.0+incompatible
)
go build
automatically adds the second require.
This is the code I have:
func main() {
s := blackfriday.Run(
[]byte("# Hello"),
blackfriday.WithRenderer(bfchroma.NewRenderer()))
fmt.Println(string(s))
}
This gives an error:
cannot use bfchroma.NewRenderer() (type *bfchroma.Renderer) as type "github.com/russross/blackfriday".Renderer in argument to "github.com/russross/blackfriday".WithRenderer:
*bfchroma.Renderer does not implement "github.com/russross/blackfriday".Renderer (wrong type for RenderFooter method)
have RenderFooter(io.Writer, *"gopkg.in/russross/blackfriday.v2".Node)
want RenderFooter(io.Writer, *"github.com/russross/blackfriday".Node)
Any ideas?
The current version of Chroma is very out-of-date.
Any chance you can upgrade to Chroma v2?
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.drone.yml
golang 1.22
golang 1.22
go.mod
go 1.20
github.com/alecthomas/chroma/v2 v2.12.0
github.com/russross/blackfriday/v2 v2.1.0
github.com/stretchr/testify v1.8.4
Went to check this library out today, however it doesn't want to go get
, due to the changes in 7130586. The switch away from gopkg.in isn't necessarily the issue, rather it seems you have switched to using go/dep in a library, without checking in vendor/
which is needed for go get
functionality to work (otherwise, Go has no idea that you want to use that specific version), IIRC.
tl;dr, when running go get
on this lib, it's fetching blackfriday master branch, not v2
:
liam:~$ go get -v -u github.com/Depado/bfchroma
github.com/Depado/bfchroma (download)
github.com/alecthomas/chroma (download)
github.com/dlclark/regexp2 (download)
github.com/danwakefield/fnmatch (download)
github.com/russross/blackfriday (download)
github.com/russross/blackfriday
github.com/Depado/bfchroma
# github.com/Depado/bfchroma
../../Depado/bfchroma/renderer.go:61:9: undefined: blackfriday.NewHTMLRenderer
../../Depado/bfchroma/renderer.go:61:28: undefined: blackfriday.HTMLRendererParameters
../../Depado/bfchroma/renderer.go:75:68: undefined: blackfriday.CodeBlockData
../../Depado/bfchroma/renderer.go:107:50: undefined: blackfriday.Node
../../Depado/bfchroma/renderer.go:107:74: undefined: blackfriday.WalkStatus
../../Depado/bfchroma/renderer.go:109:7: undefined: blackfriday.CodeBlock
../../Depado/bfchroma/renderer.go:120:51: undefined: blackfriday.Node
../../Depado/bfchroma/renderer.go:121:8: r.Base.RenderHeader undefined (type blackfriday.Renderer has no field or method RenderHeader)
../../Depado/bfchroma/renderer.go:125:51: undefined: blackfriday.Node
../../Depado/bfchroma/renderer.go:126:8: r.Base.RenderFooter undefined (type blackfriday.Renderer has no field or method RenderFooter)
../../Depado/bfchroma/renderer.go:126:8: too many errors
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.