Documentation ¶
Index ¶
Constants ¶
const ( CbPrompt = template.HTML(" ►") TmplName = "tmplCodeBlock" )
Variables ¶
var ( //go:embed codeblock.js Js string //go:embed codeblock.css Css string )
Functions ¶
Types ¶
type MdRipCbRenderer ¶
MdRipCbRenderer 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 MdRipCodeBlock. This all seems odd, but it appears to work.
func (*MdRipCbRenderer) RegisterFuncs ¶
func (r *MdRipCbRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)
RegisterFuncs implements NodeRenderer.RegisterFuncs.
type MdRipCodeBlock ¶
type MdRipCodeBlock struct {
ast.FencedCodeBlock
}
A MdRipCodeBlock 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 sometimes 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 MdRipCodeBlock. 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
Annoyingly, since we replace the FencedCodeBlock with MdRipCodeBlock, the goldmark code highlighter won't be invoked.
TODO: rebuild the AST so that instead of replacing a FencedCodeBLock
with a MdRipCodeBlock, we nest the FencedCodeBlock inside the MdRipCodeBlock.
func NewMdRipCodeBlock ¶
func NewMdRipCodeBlock(fcb *ast.FencedCodeBlock) *MdRipCodeBlock
NewMdRipCodeBlock return a new MdRipCodeBlock AST node.
func (*MdRipCodeBlock) GetBlockIndex ¶
func (n *MdRipCodeBlock) GetBlockIndex() (int, error)
func (*MdRipCodeBlock) GetTitle ¶
func (n *MdRipCodeBlock) GetTitle() (string, error)
func (*MdRipCodeBlock) Kind ¶
func (n *MdRipCodeBlock) Kind() ast.NodeKind
Kind implements Node.Kind.
func (*MdRipCodeBlock) SetBlockIndex ¶
func (n *MdRipCodeBlock) SetBlockIndex(i int)
func (*MdRipCodeBlock) SetFileIndex ¶
func (n *MdRipCodeBlock) SetFileIndex(i int)
func (*MdRipCodeBlock) SetTitle ¶
func (n *MdRipCodeBlock) SetTitle(s string)