Documentation ¶
Overview ¶
Package bfchroma provides an easy and extensible blackfriday renderer that uses the chroma syntax highlighter to render code blocks.
Index ¶
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())) 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 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 bf.Renderer Autodetect bool ChromaOptions []html.Option Style *chroma.Style Formatter *html.Formatter }
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()), ) h := bf.Run([]byte(md), bf.WithRenderer(r)) fmt.Println(string(h))
Output:
func (*Renderer) RenderFooter ¶
RenderFooter satisfies the Renderer interface
func (*Renderer) RenderHeader ¶
RenderHeader satisfies the Renderer interface
func (*Renderer) RenderNode ¶
RenderNode satisfies the Renderer interface
func (*Renderer) RenderWithChroma ¶
RenderWithChroma will render the given text to the w io.Writer