Documentation ¶
Overview ¶
Package bfchroma provides an easy and extensible blackfriday renderer that uses the chroma syntax highlighter to render code blocks.
Index ¶
- type Option
- type Renderer
- func (r *Renderer) ChromaCSS(w io.Writer) error
- func (r *Renderer) RenderFooter(w io.Writer, ast ast.Node)
- func (r *Renderer) RenderHeader(w io.Writer, ast ast.Node)
- func (r *Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.WalkStatus
- func (r *Renderer) RenderWithChroma(w io.Writer, text []byte, data ast.CodeBlock) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(r *Renderer)
Option defines the functional option type
func ChromaOptions ¶
ChromaOptions allows to pass Chroma html.Option such as Standalone() WithClasses(), ClassPrefix(prefix)...
Example ¶
md := "```go\npackage main\n\nfunc main() {\n}\n```" r := NewRenderer(ChromaOptions(html.WithLineNumbers(true))) h := bf.Run([]byte(md), bf.WithRenderer(r)) fmt.Println(string(h))
Output:
func ChromaStyle ¶
ChromaStyle is an option to directly set the style of the renderer using a chroma style instead of a string
Example ¶
md := "```go\npackage main\n\nfunc main() {\n}\n```" r := NewRenderer(ChromaStyle(styles.GitHub)) h := bf.Run([]byte(md), bf.WithRenderer(r)) fmt.Println(string(h))
Output:
func EmbedCSS ¶ added in v1.4.0
func EmbedCSS() Option
EmbedCSS will embed CSS needed for html.WithClasses() in beginning of the document
func Extend ¶
Extend allows to specify the blackfriday renderer which is extended
Example ¶
md := "```go\npackage main\n\nfunc main() {\n}\n```" b := bf.NewHTMLRenderer(bf.HTMLRendererParameters{ Flags: bf.CommonHTMLFlags, }) r := NewRenderer(Extend(b)) h := bf.Run([]byte(md), bf.WithRenderer(r)) fmt.Println(string(h))
Output:
func Style ¶
Style is a function option allowing to set the style used by chroma Default : "monokai"
Example ¶
md := "```go\npackage main\n\nfunc main() {\n}\n```" r := NewRenderer(Style("github")) h := bf.Run([]byte(md), bf.WithRenderer(r)) fmt.Println(string(h))
Output:
func WithoutAutodetect ¶
func WithoutAutodetect() Option
WithoutAutodetect disables chroma's language detection when no codeblock extra information is given. It will fallback to a sane default instead of trying to detect the language.
Example ¶
md := "```\npackage main\n\nfunc main() {\n}\n```" r := NewRenderer(WithoutAutodetect()) h := bf.Run([]byte(md), bf.WithRenderer(r)) fmt.Println(string(h))
Output:
type Renderer ¶
type Renderer struct { Base md.Renderer Autodetect bool ChromaOptions []html.Option Style *chroma.Style Formatter *html.Formatter // contains filtered or unexported fields }
Renderer is a custom Blackfriday renderer that uses the capabilities of chroma to highlight code with triple backtick notation
func NewRenderer ¶
NewRenderer will return a new bfchroma renderer with sane defaults
Example ¶
// Complex example on how to initialize the renderer md := "```go\npackage main\n\nfunc main() {\n}\n```" r := NewRenderer( Extend(bf.NewHTMLRenderer(bf.HTMLRendererParameters{ Flags: bf.CommonHTMLFlags, })), WithoutAutodetect(), ChromaStyle(styles.GitHub), ChromaOptions(html.WithLineNumbers(true)), ) h := bf.Run([]byte(md), bf.WithRenderer(r)) fmt.Println(string(h))
Output:
func (*Renderer) ChromaCSS ¶ added in v1.4.0
ChromaCSS returns CSS used with chroma's html.WithClasses() option
func (*Renderer) RenderFooter ¶
RenderFooter satisfies the Renderer interface
func (*Renderer) RenderHeader ¶
RenderHeader satisfies the Renderer interface
func (*Renderer) RenderNode ¶
RenderNode satisfies the Renderer interface