highlight

package module
v0.0.0-...-34974eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2017 License: MIT Imports: 15 Imported by: 4

README

go-highlight GoDoc Build Status

A Go (Golang) code syntax highlighting library. It uses automatically converted highlight.js language definitions.

Usage

package main

import "github.com/d4l3k/go-highlight"

func main() {
  highlight.Highlight("go", `
    package main

    import "fmt"

    func main() {
      fmt.Println("Duck!")
    }
  `)
  /*
    <keyword>package</keyword> main

    <keyword>import</keyword> <string>"fmt"</string>

    <keyword>func</keyword> main() {
      fmt.Println(<string>"Duck!"</string>)
    }
  */
}

The code written by Tristan Rice is licensed under the MIT license.

The language definitions are ported from highlight.js which is licensed under the BSD licence.

Documentation

Index

Constants

View Source
const (
	Keyword = "keyword"
	Literal = "literal"
	BuiltIn = "built_in"
)

The text highlight classes.

Variables

View Source
var Workers = 1

Workers is the number of workers to use to detect the language.

Functions

func Detect

func Detect(code []byte) (string, error)

Detect returns the detected language.

func HTML

func HTML(lang string, code []byte) ([]byte, error)

HTML highlights a piece of code in HTML.

func Term

func Term(lang string, code []byte) ([]byte, error)

Term highlights a piece of code for rendering in the terminal.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL