Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use alecthomas/chroma for syntax highlighting #15

Open
n10v opened this issue Nov 5, 2017 · 4 comments
Open

Use alecthomas/chroma for syntax highlighting #15

n10v opened this issue Nov 5, 2017 · 4 comments

Comments

@n10v
Copy link

n10v commented Nov 5, 2017

Hello, @shurcooL!
What do you think about using github.com/alecthomas/chroma for syntax highlighting? It supports a bunch of languages and works great

@dmitshur
Copy link
Member

dmitshur commented Nov 7, 2017

Hi @BoGeM, thanks for the question/suggestion.

I've heard of that library and looked at it briefly. At a glance, it seems to offer a lot of functionality.

I personally don't need support for highlighting many other languages, and the existing highlighting works well for my needs, so this is a low priority for me.

However, I expect that it can be very helpful to other people who care about highlighting for additional languages, and it gets this package closer to implementing the GFM spec/behavior fully.

One main aspect that needs to be taken into account is the library size. This github_flavored_markdown package is currently used for rendering GFM on the frontend in a few applications. If integrating chroma increases the overall code size significantly, it might not be viable to integrate it unconditionally (at that point, we'd have to consider some sort of pluggable interface). If integrating it doesn't increase the size very much, then it's not a problem.

Investigating the size increase would be neccessary to evaluate it.

@n10v
Copy link
Author

n10v commented Nov 7, 2017

Ok. Later I will make a PR for this ncluding the investigation of the library‘s size.

@n10v
Copy link
Author

n10v commented Nov 7, 2017

Oh yes. I just tested it on my system and investigated, that the size of alecthomas/chroma is really huge.

Consider this script:

package main

import markdown "github.com/shurcooL/github_flavored_markdown"

func main() {
	markdown.Markdown([]byte{})
}

Size of the binary before adding chroma:

$ go build -a ./script.go
$ du -sh ./script
 3,7M    script

After:

$ go build -a ./script.go
$ du -sh ./script
 19M    script

So the size of library increased from 3.7MB to 19MB (~5x).

@dmitshur
Copy link
Member

I see, thanks for investigating that.

The size increase is definitely substantial enough to say that it's not going to be possible to add chroma highlighting support unconditionally. In order to add support for it, we will need to come up with an interface where it's possible to supply custom highlighting providers, and a chroma-based highlighter would be one of the things you could supply.

That way, users who want the more comprehensive support for highlighting can have it, but others wouldn't need to pay the price in dependency size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants