syntax

package module
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: BSD-3-Clause Imports: 7 Imported by: 4

README

syntax

Syntax highlight text.

This is a fork of syntaxhighlight.

Modifications have been made to output syntax highlighted text in a format that suites textoutput instead of HTML, so that it can be used in terminal applications.

  • License: BSD 3-Clause
  • Version: 1.8.0

Documentation

Overview

Package syntax provides syntax highlighting for code. It currently uses a language-independent lexer and performs decently on JavaScript, Java, Ruby, Python, Go, and C.

Index

Constants

This section is empty.

Variables

View Source
var DefaultTextConfig = TextConfig{
	String:        "lightwhite",
	Keyword:       "red",
	Comment:       "darkgray",
	Type:          "white",
	Literal:       "white",
	Punctuation:   "red",
	Plaintext:     "white",
	Tag:           "white",
	TextTag:       "white",
	TextAttrName:  "white",
	TextAttrValue: "white",
	Decimal:       "red",
	AndOr:         "red",
	Dollar:        "white",
	Star:          "white",
	Whitespace:    "",
	Class:         "white",
	Private:       "red",
	Public:        "red",
	Protected:     "red",
	AssemblyEnd:   "lightyellow",
}

DefaultTextConfig provides class names that match the color names of textoutput tags: https://github.com/xyproto/textoutput

View Source
var Keywords = map[string]struct{}{}/* 186 elements not displayed */

Functions

func Annotate

func Annotate(src []byte, a Annotator, assemblyMode bool) (annotate.Annotations, error)

func AsText

func AsText(src []byte, assemblyMode bool, options ...Option) ([]byte, error)

AsText converts source code into an Text-highlighted version; It accepts optional configuration parameters to control rendering (see OrderedList as one example)

func NewScanner

func NewScanner(src []byte) *scanner.Scanner

NewScanner is a helper that takes a []byte src, wraps it in a reader and creates a Scanner.

func NewScannerReader

func NewScannerReader(src io.Reader) *scanner.Scanner

NewScannerReader takes a reader src and creates a Scanner.

func Print

func Print(s *scanner.Scanner, w io.Writer, p Printer, assemblyMode bool) error

Types

type Annotator

type Annotator interface {
	Annotate(start int, kind Kind, tokText string) (*annotate.Annotation, error)
}

type Kind

type Kind uint8

Kind represents a syntax highlighting kind (class) which will be assigned to tokens. A syntax highlighting scheme (style) maps text style properties to each token kind.

const (
	Whitespace Kind = iota
	String
	Keyword
	Comment
	Type
	Literal
	Punctuation
	Plaintext
	Tag
	TextTag
	TextAttrName
	TextAttrValue
	Decimal
	AndOr
	Star
	Class
	Private
	Public
	Protected
	Dollar
	AssemblyEnd
)

A set of supported highlighting kinds

func (Kind) GoString

func (i Kind) GoString() string

type Option

type Option func(options *TextConfig)

Option is a type of the function that can modify one or more of the options in the TextConfig structure.

type Printer

type Printer interface {
	Print(w io.Writer, kind Kind, tokText string) error
}

Printer implements an interface to render highlighted output (see TextPrinter for the implementation of this interface)

type TextAnnotator

type TextAnnotator TextConfig

func (TextAnnotator) Annotate

func (a TextAnnotator) Annotate(start int, kind Kind, tokText string) (*annotate.Annotation, error)

type TextConfig

type TextConfig struct {
	String        string
	Keyword       string
	Comment       string
	Type          string
	Literal       string
	Punctuation   string
	Plaintext     string
	Tag           string
	TextTag       string
	TextAttrName  string
	TextAttrValue string
	Decimal       string
	AndOr         string
	Dollar        string
	Star          string
	Whitespace    string
	Class         string
	Private       string
	Public        string
	Protected     string
	AssemblyEnd   string
}

TextConfig holds the Text class configuration to be used by annotators when highlighting code.

func (TextConfig) GetClass

func (c TextConfig) GetClass(kind Kind) string

GetClass returns the set class for a given token Kind.

type TextPrinter

type TextPrinter TextConfig

TextPrinter implements Printer interface and is used to produce Text-based highligher

func (TextPrinter) Print

func (p TextPrinter) Print(w io.Writer, kind Kind, tokText string) error

Print is the function that emits highlighted source code using <color>...<off> wrapper tags

Directories

Path Synopsis
cmd
hicat command

Jump to

Keyboard shortcuts

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