Socket
Socket
Sign inDemoInstall

github.com/saward/mdchroma

Package Overview
Dependencies
5
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/saward/mdchroma

Package bfchroma provides an easy and extensible blackfriday renderer that uses the chroma syntax highlighter to render code blocks.


Version published

Readme

Source

mdchroma

Integrating Chroma syntax highlighter as a Go Markdown renderer.

Install and prerequisites

This project requires and uses the Go Markdown package.

$ go get -u github.com/saward/mdchroma

This project uses the module approach of go 1.11

Features

This renderer integrates chroma to highlight code with triple backtick notation. It will try to use the given language when available otherwise it will try to detect the language. If none of these two method works it will fallback to sane defaults.

This is a fork of the mdchroma package, modified to instead work with Go Markdown.

Usage

output := markdown.ToHTML(md, nil, mdchroma.NewRenderer())

Examples

package main

import (
	"fmt"

	chroma "github.com/saward/mdchroma"
	"github.com/gomarkdown/markdown"
)

var md = "This is some sample code.\n\n```go\n" +
	`func main() {
	fmt.Println("Hi")
}
` + "```"

func main() {
	html := markdown.ToHTML([]byte(md), nil, chroma.NewRenderer())
	fmt.Println(string(html))
}

Will output :

<p>This is some sample code.</p>
<pre style="color:#f8f8f2;background-color:#272822"><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() {
<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;Hi&#34;</span>)
}
</pre>

FAQs

Last updated on 30 Dec 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc