bfplus

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: MIT Imports: 11 Imported by: 0

README

bfplus

Blackfriday Renderer that supports admonitions, auto-heading links and code highlighting using Chroma

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdmonitionRenderer

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

AdmonitionRenderer is a custom Blackfriday renderer that attempts to find admonition style markdown and render it

func (*AdmonitionRenderer) RenderNode

func (r *AdmonitionRenderer) RenderNode(w io.Writer, node *bf.Node, entering bool, base bf.Renderer) bf.WalkStatus

RenderNode will render the node and try to find admonitions

type AnchorOption

type AnchorOption func(r *AnchorRenderer)

AnchorOption defines the functional option type for the code rendering

func Classes

func Classes(in ...string) AnchorOption

Classes is a list of classes that will be applied to the anchor. Default: []string{"anchor"}

func Content

func Content(s string) AnchorOption

Content is what will be displayed. This can be any HTML code, or a simple char. Default: "#"

func IDPrefix

func IDPrefix(s string) AnchorOption

IDPrefix is a prefix that will be put before the ID of the matching heading content. Although you can set it to "", that will duplicate IDs in your DOM, so it not a good practice. Always use a prefix. Default: "a-"

type AnchorRenderer

type AnchorRenderer struct {
	IDPrefix string
	Classes  []string
	Content  string
}

AnchorRenderer contains the required metadata for proper code rendering

func (*AnchorRenderer) RenderNode

func (a *AnchorRenderer) RenderNode(w io.Writer, node *bf.Node, entering bool)

RenderNode is a simple function that needs to be called at the right moment when rendering markdown. Note that the AnchorRenderer itself doesn't implement all the methods required to be considered a true renderer. This is by design.

type CodeOption

type CodeOption func(r *CodeRenderer)

CodeOption defines the functional option type for the code rendering

func ChromaOptions

func ChromaOptions(options ...html.Option) CodeOption

ChromaOptions allows to pass Chroma html.Option such as Standalone() WithClasses(), ClassPrefix(prefix)...

func ChromaStyle

func ChromaStyle(s *chroma.Style) CodeOption

ChromaStyle is an option to directly set the style of the renderer using a chroma style instead of a string

func Style

func Style(s string) CodeOption

Style is a function option allowing to set the style used by chroma Default : "monokai"

func WithoutAutodetect

func WithoutAutodetect() CodeOption

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.

type CodeRenderer

type CodeRenderer struct {
	Autodetect    bool
	ChromaOptions []html.Option
	Style         *chroma.Style
	Formatter     *html.Formatter
}

CodeRenderer contains the required metadata for proper code rendering

func (*CodeRenderer) RenderWithChroma

func (r *CodeRenderer) RenderWithChroma(w io.Writer, text []byte, data bf.CodeBlockData) error

RenderWithChroma will render the given text to the w io.Writer

type Option

type Option func(r *Renderer)

Option defines the functional option type

func Extend

func Extend(br bf.Renderer) Option

Extend allows to specify the blackfriday renderer which is extended

func WithAdmonition

func WithAdmonition() Option

WithAdmonition enables admonition support

func WithCodeHighlighting

func WithCodeHighlighting(options ...CodeOption) Option

WithCodeHighlighting enables syntax highlighting using Chroma

func WithHeadingAnchors

func WithHeadingAnchors(options ...AnchorOption) Option

WithHeadingAnchors enables anchor insertion for headings

type Renderer

type Renderer struct {
	Base bf.Renderer // Base renderer, the one we will extend

	Highlighter *CodeRenderer
	Anchor      *AnchorRenderer
	Admonition  *AdmonitionRenderer
}

Renderer extends a base renderer, allowing to add a custom anchor element inside every heading block with a matching `a-id` ID and an `anchor` class for further CSS customization

func NewRenderer

func NewRenderer(options ...Option) *Renderer

NewRenderer returns a new renderer with all the options applied

func (*Renderer) RenderFooter

func (r *Renderer) RenderFooter(w io.Writer, ast *bf.Node)

RenderFooter satisfies the Renderer interface

func (*Renderer) RenderHeader

func (r *Renderer) RenderHeader(w io.Writer, ast *bf.Node)

RenderHeader satisfies the Renderer interface

func (*Renderer) RenderNode

func (r *Renderer) RenderNode(w io.Writer, node *bf.Node, entering bool) bf.WalkStatus

RenderNode satisfies the Renderer interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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