chroma

package
Version: v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package chroma provides a basic plugin for implementing syntax highlighting using Chroma (https://github.com/alecthomas/chroma).

To use this plugin, pass `--plugin github.com/vito/booklit/chroma/plugin` and use it like so:

\use-plugin{chroma}

\syntax{go}{{{
package chroma

// ...
}}}

An optional style name may be specified as the third argument. To use a custom style you may write your own plugin that embeds this plugin, or re-assign github.com/alecthomas/chroma/styles.Fallback to change the default.

Index

Constants

This section is empty.

Variables

View Source
var Booklit = lexers.Register(MustNewLexer(
	&Config{
		Name:      "Booklit",
		Aliases:   []string{"booklit"},
		Filenames: []string{"*.lit"},
		MimeTypes: []string{"text/x-booklit"},
	},
	Rules{
		"root": {
			{`[^\\{}]+`, Text, nil},
			{`\{\{\{`, StringDouble, Push("verbatim")},
			{`\{-`, CommentMultiline, Push("comment")},
			{`[{}]`, NameBuiltin, nil},
			{`\\([a-z-]+)`, Keyword, nil},
			{`\\[\\{}]+`, Text, nil},
		},
		"verbatim": {
			{`\}\}\}`, StringDouble, Pop(1)},
			{`[^}]+`, StringDouble, nil},
			{`}[^\}]`, StringDouble, nil},
		},
		"comment": {
			{`[^-{}]+`, CommentMultiline, nil},
			{`\{-`, CommentMultiline, Push()},
			{`-\}`, CommentMultiline, Pop(1)},
			{`[-{}]`, CommentMultiline, nil},
		},
	},
))

Booklit is a lexer for Booklit syntax.

Functions

func NewPlugin

func NewPlugin(section *booklit.Section) booklit.Plugin

Types

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

func (Plugin) Syntax

func (plugin Plugin) Syntax(language string, code booklit.Content, styleName ...string) (booklit.Content, error)

func (Plugin) SyntaxTransform

func (plugin Plugin) SyntaxTransform(language string, code booklit.Content, chromaStyle *chroma.Style, transformers ...Transformer) (booklit.Content, error)

type Transformer

type Transformer struct {
	Pattern   *regexp.Regexp
	Transform func(string) booklit.Content
}

func (Transformer) TransformAll

func (t Transformer) TransformAll(str string) booklit.Sequence

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to