Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/yuin/goldmark-highlighting/v2

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/yuin/goldmark-highlighting/v2

  • v2.0.0-20230729083705-37449abec8cc
  • Source
  • Go
  • Socket score

Version published
Created
Source

goldmark-highlighting

goldmark-highlighting is an extension for the goldmark that adds syntax-highlighting to the fenced code blocks.

goldmark-highlighting uses chroma as a syntax highlighter.

Installation

go get github.com/yuin/goldmark-highlighting/v2

Usage

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

FAQs

Package last updated on 29 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc