Documentation
¶
Overview ¶
package highlighting is a extension for the goldmark(http://github.com/yuin/goldmark).
This extension adds syntax-highlighting to the fenced code blocks using chroma(https://github.com/alecthomas/chroma).
Index ¶
- Variables
- func NewHTMLRenderer(opts ...HTMLRendererOption) html.Extension
- func NewParser() parser.Extension
- func WithCSSMap(rc renderer.Context, m map[string]string) renderer.Context
- type ExcludeFunc
- type HTMLRendererOption
- func WithCodeBlockFormatterOptions(f func(*ast.CodeBlock, []byte, renderer.Context) []chromahtml.Option) HTMLRendererOption
- func WithCustomStyle(style *chroma.Style) HTMLRendererOption
- func WithExcludeFunc(f ExcludeFunc) HTMLRendererOption
- func WithExcludeLanguages(langs ...string) HTMLRendererOption
- func WithFormatterOptions(opts ...chromahtml.Option) HTMLRendererOption
- func WithGuessLanguage(b ...bool) HTMLRendererOption
- func WithStyle(style string) HTMLRendererOption
Constants ¶
This section is empty.
Variables ¶
var HTMLRenderer = NewHTMLRenderer()
HTMLRenderer is a default html.Extension for highlighted fenced code blocks.
Deprecated: use NewHTMLRenderer instead.
var Parser = NewParser()
Parser is a default parser.Extension for highlighted fenced code blocks.
Deprecated: use NewParser instead.
Functions ¶
func NewHTMLRenderer ¶
func NewHTMLRenderer(opts ...HTMLRendererOption) html.Extension
NewHTMLRenderer returns a new html.Extension .
func NewParser ¶
NewParser returns a new parser.Extension for highlighted fenced code blocks.
func WithCSSMap ¶
WithCssMap sets `map[string]string` reference for CSS data in the renderer.Context.
If `WithClasses()`(FormatterOption) is enabled, renderer will write CSS data corresponds to the style to the given map. Keys are style names, and values are CSS data.
Types ¶
type ExcludeFunc ¶ added in v3.1.0
ExcludeFunc is a function type that can be used to exclude certain code blocks from being highlighted.
type HTMLRendererOption ¶
type HTMLRendererOption func(*htmlRendererConfig)
HTMLRendererOption is a functional option for HTMLRenderer.
func WithCodeBlockFormatterOptions ¶
func WithCodeBlockFormatterOptions(f func(*ast.CodeBlock, []byte, renderer.Context) []chromahtml.Option) HTMLRendererOption
WithCodeBlockFormatterOptions is a functional option that allows set Chroma options per code block.
func WithCustomStyle ¶
func WithCustomStyle(style *chroma.Style) HTMLRendererOption
WithCustomStyle is a functional option that changes highlighting style.
Pass in a custom Chroma style. If this is not nil, the Style string will be ignored.
func WithExcludeFunc ¶ added in v3.1.0
func WithExcludeFunc(f ExcludeFunc) HTMLRendererOption
WithExcludeFunc is a functional option that sets a function to exclude certain code blocks from being highlighted.
func WithExcludeLanguages ¶ added in v3.1.0
func WithExcludeLanguages(langs ...string) HTMLRendererOption
WithExcludeLanguages is a functional option that sets a list of languages to exclude from being highlighted.
func WithFormatterOptions ¶
func WithFormatterOptions(opts ...chromahtml.Option) HTMLRendererOption
WithFormatterOptions is a functional option that wraps chroma HTML formatter options.
See https://github.com/alecthomas/chroma#the-html-formatter for details.
func WithGuessLanguage ¶
func WithGuessLanguage(b ...bool) HTMLRendererOption
WithGuessLanguage is a functional option that toggles language guessing if none provided.
If the guessing fails, we will fall back to a text lexer. Note that while Chroma's API supports language guessing, the implementation is not there yet, so you will currently always get the basic text lexer.
func WithStyle ¶
func WithStyle(style string) HTMLRendererOption
WithStyle is a functional option that changes highlighting style.
Supported styles are defined under https://github.com/alecthomas/chroma/tree/master/formatters.