codeblock

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 8 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 HighlightedCbRenderer

type HighlightedCbRenderer struct {
	Writer html.Writer
}

HighlightedCbRenderer is an implementation of renderer.NodeRenderer, but despite the name of the interface, instances of this interface 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 HighlightedCodeBlock.

func (*HighlightedCbRenderer) RegisterFuncs

RegisterFuncs implements NodeRenderer.RegisterFuncs.

type HighlightedCodeBlock

type HighlightedCodeBlock struct {
	ast.BaseBlock
	FileIndex  int
	BlockIndex int
	Title      string
}

HighlightedCodeBlock represents a code block one might be able to run.

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. Other times we want to do a special rendering, that encourages copy/paste and execution.

In the latter case, we replace the AST node instance of a native FencedCodeBlock with an instance of HighlightedCodeBlock that has the FencedCodeBlock as its lone child in the AST. The HighlightedCodeBlock must register its own Kind and renderer with the goldmark infrastructure.

func (*HighlightedCodeBlock) Dump

func (n *HighlightedCodeBlock) Dump(source []byte, level int)

Dump implements Node.Dump.

func (*HighlightedCodeBlock) Kind

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

Kind implements Node.Kind.

Jump to

Keyboard shortcuts

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