https://github.com/yuin/goldmark-highlighting
A Syntax highlighting extension for the goldmark markdown parser.
https://github.com/yuin/goldmark-highlighting
Last synced: 8 months ago
JSON representation
A Syntax highlighting extension for the goldmark markdown parser.
- Host: GitHub
- URL: https://github.com/yuin/goldmark-highlighting
- Owner: yuin
- License: mit
- Created: 2019-07-11T09:10:59.000Z (over 6 years ago)
- Default Branch: v2
- Last Pushed: 2023-10-03T03:09:29.000Z (over 2 years ago)
- Last Synced: 2025-04-12T16:52:19.887Z (9 months ago)
- Language: Go
- Size: 56.6 KB
- Stars: 109
- Watchers: 3
- Forks: 17
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
goldmark-highlighting
=========================
goldmark-highlighting is an extension for the [goldmark](http://github.com/yuin/goldmark)
that adds syntax-highlighting to the fenced code blocks.
goldmark-highlighting uses [chroma](https://github.com/alecthomas/chroma) as a
syntax highlighter.
Installation
--------------------
```
go get github.com/yuin/goldmark-highlighting/v2
```
Usage
--------------------
```go
package main
import (
"bytes"
"fmt"
"github.com/yuin/goldmark"
chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
highlighting "github.com/yuin/goldmark-highlighting/v2"
)
func main() {
mdsrc := `
Title
=======
` + "```" + `
func main() {
fmt.Println("ok")
}
` + "```" + `
`
// Simple usage
markdown := goldmark.New(
goldmark.WithExtensions(
highlighting.Highlighting,
),
)
var buf bytes.Buffer
if err := markdown.Convert([]byte(mdsrc), &buf); err != nil {
panic(err)
}
title := buf.String()
fmt.Print(title)
// Custom configuration
markdown2 := goldmark.New(
goldmark.WithExtensions(
highlighting.NewHighlighting(
highlighting.WithStyle("monokai"),
highlighting.WithFormatOptions(
chromahtml.WithLineNumbers(true),
),
),
),
)
var buf2 bytes.Buffer
if err := markdown2.Convert([]byte(mdsrc), &buf2); err != nil {
panic(err)
}
title2 := buf2.String()
fmt.Print(title2)
}
```
License
--------------------
MIT
Author
--------------------
Yusuke Inuzuka