Documentation ¶
Overview ¶
Package syntaxhighlight provides syntax highlighting for code. It currently uses a language-independent lexer and performs decently on JavaScript, Java, Ruby, Python, Go, and C.
Example ¶
package main import ( "fmt" "os" "github.com/sourcegraph/syntaxhighlight" ) func main() { src := []byte(` /* hello, world! */ var a = 3; // b is a cool function function b() { return 7; }`) highlighted, err := syntaxhighlight.AsHTML(src) if err != nil { fmt.Println(err) os.Exit(1) } fmt.Println(string(highlighted))
Output:
Index ¶
- Constants
- Variables
- func Annotate(src []byte, a Annotator) (annotate.Annotations, error)
- func AsHTML(src []byte) ([]byte, error)
- func NewScanner(src []byte) *scanner.Scanner
- func Print(s *scanner.Scanner, w io.Writer, p Printer) error
- type Annotator
- type HTMLAnnotator
- type HTMLConfig
- type HTMLPrinter
- type Printer
Examples ¶
Constants ¶
View Source
const ( WHITESPACE = iota STRING KEYWORD COMMENT TYPE LITERAL PUNCTUATION PLAINTEXT TAG HTMLTAG HTMLATTRNAME HTMLATTRVALUE DECIMAL )
Variables ¶
View Source
var DefaultHTMLConfig = HTMLConfig{
String: "str",
Keyword: "kwd",
Comment: "com",
Type: "typ",
Literal: "lit",
Punctuation: "pun",
Plaintext: "pln",
Tag: "tag",
HTMLTag: "htm",
HTMLAttrName: "atn",
HTMLAttrValue: "atv",
Decimal: "dec",
}
DefaultHTMLConfig's class names match those of [google-code-prettify](https://code.google.com/p/google-code-prettify/).
View Source
var Keywords = map[string]struct{}{}/* 173 elements not displayed */
Functions ¶
func NewScanner ¶
Types ¶
type HTMLAnnotator ¶
type HTMLAnnotator HTMLConfig
func (HTMLAnnotator) Annotate ¶
func (a HTMLAnnotator) Annotate(start int, kind int, tokText string) (*annotate.Annotation, error)
type HTMLConfig ¶
type HTMLPrinter ¶
type HTMLPrinter HTMLConfig
Click to show internal directories.
Click to hide internal directories.