codeblock

package
v2.0.0-rc11 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CbPrompt = template.HTML(" ►")
	TmplName = "tmplCodeBlock"
)

Variables

View Source
var (
	//go:embed codeblock.js
	Js string
	//go:embed codeblock.css
	Css string
)

Functions

func AsTmpl

func AsTmpl() string

Types

type MyFcbRenderer

type MyFcbRenderer struct {
	Writer html.Writer
}

MyFcbRenderer is an implementation of renderer.NodeRenderer, but despite the name of the interface, instances of this don't actually render anything. All an instance does is provide a method that registers a "Kind" with a rendering function. The rendering function can live anywhere, and in this case it lives in an instance of MyFencedCodeBlock. This all seems odd, but it appears to work.

func (*MyFcbRenderer) RegisterFuncs

func (r *MyFcbRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)

RegisterFuncs implements NodeRenderer.RegisterFuncs.

type MyFencedCodeBlock

type MyFencedCodeBlock struct {
	ast.FencedCodeBlock
}

A MyFencedCodeBlock struct represents a fenced code block of Markdown text.

Sometimes we want to render a fenced code block using the normal default fenced code block rendered, e.g. when a code block is "protected" inside a blockquote.

But more often we want to do a special rendering, that encourages copy/paste, execution, etc.

When we do want a special rendering, we replace the AST node instance of a native FencedCodeBlock with an instance of MyFencedCodeBlock. The latter must register its own Kind and renderer with the goldmark infrastructure.

FWIW, in goldMark's interfaces, there doesn't seem to be a way to call a "native" renderer (in particular, the FencedCodeBlock renderer) from a custom renderer function, because a customer renderer function cannot see

  • its own encapsulating renderer at goldmark/renderer/renderer.go:L135
  • the global renderer function lookup table held inside the encapsulating renderer
  • the private "renderFencedCodeBlock" function near goldmark/renderer/html/html.go:L386

func NewMyFencedCodeBlock

func NewMyFencedCodeBlock(fcb *ast.FencedCodeBlock) *MyFencedCodeBlock

NewMyFencedCodeBlock return a new MyFencedCodeBlock node.

func (*MyFencedCodeBlock) GetBlockIndex

func (n *MyFencedCodeBlock) GetBlockIndex() (int, error)

func (*MyFencedCodeBlock) GetTitle

func (n *MyFencedCodeBlock) GetTitle() (string, error)

func (*MyFencedCodeBlock) Kind

func (n *MyFencedCodeBlock) Kind() ast.NodeKind

Kind implements Node.Kind.

func (*MyFencedCodeBlock) SetBlockIndex

func (n *MyFencedCodeBlock) SetBlockIndex(i int)

func (*MyFencedCodeBlock) SetFileIndex

func (n *MyFencedCodeBlock) SetFileIndex(i int)

func (*MyFencedCodeBlock) SetTitle

func (n *MyFencedCodeBlock) SetTitle(s string)

Jump to

Keyboard shortcuts

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