mdrender

package
v0.0.0-...-bd1a654 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderWYSIWYG

func RenderWYSIWYG(ctx context.Context, buffer *gtk.TextBuffer)

RenderWYSIWYG is a convenient function.

func SetIter

func SetIter(iter *gtk.TextIter, src []byte, byteOffset int)

SetIter sets the given iterator to the given byte offset. It is the most correct way to convert an ast.Node's position to the iterator's.

func WithState

func WithState(ctx context.Context, state *block.ContainerState) context.Context

WithState adds a new container state to the given context.

Types

type MarkdownViewer

type MarkdownViewer struct {
	*block.Viewer
}

MarkdownViewer extends a block.Viewer to view Markdown. A Markdown viewer is immutable.

func NewMarkdownViewer

func NewMarkdownViewer(ctx context.Context, src []byte, n ast.Node, opts ...OptionFunc) *MarkdownViewer

NewMarkdownViewer creates a new MarkdownViewer.

type OptionFunc

type OptionFunc func(r *Renderer)

OptionFunc is a function type for any options that modify Renderer's internals.

func WithFallbackRenderer

func WithFallbackRenderer(renderer RendererFunc) OptionFunc

WithFallbackRenderer adds a new renderer that is called on any unhandled or unknown node.

func WithRenderer

func WithRenderer(kind ast.NodeKind, renderer RendererFunc) OptionFunc

WithRenderer adds a new renderer.

type Renderer

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

Renderer is a rendering instance.

func NewRenderer

func NewRenderer(src []byte, state *block.ContainerState, opts ...OptionFunc) *Renderer

NewRenderer creates a new renderer.

func (*Renderer) InsertSegments

func (r *Renderer) InsertSegments(text *block.TextBlock, segs *text.Segments)

InsertSegments inserts the given text segments into the buffer.

func (*Renderer) Render

func (r *Renderer) Render(ctx context.Context, n ast.Node) ast.WalkStatus

Render renders n recursively.

func (*Renderer) RenderChildren

func (r *Renderer) RenderChildren(ctx context.Context, n ast.Node) ast.WalkStatus

RenderChildren renders all of n's children.

func (*Renderer) RenderChildrenWithTag

func (r *Renderer) RenderChildrenWithTag(ctx context.Context, n ast.Node, tagName string) ast.WalkStatus

RenderChildrenWithTag calls RenderChildren wrapped within the given tag.

func (*Renderer) RenderOnce

func (r *Renderer) RenderOnce(ctx context.Context, n ast.Node) ast.WalkStatus

RenderOnce renders a single node.

func (*Renderer) RenderSiblings

func (r *Renderer) RenderSiblings(ctx context.Context, first ast.Node) ast.WalkStatus

RenderSiblings renders all siblings in n and returns SkipChildren if everything is successfully rendered.

func (*Renderer) Source

func (r *Renderer) Source() []byte

Source returns the source bytes slice.

func (*Renderer) State

func (r *Renderer) State(ctx context.Context) *block.ContainerState

State returns the container state associated with the given context, or it returns the default state.

type RendererFunc

type RendererFunc func(ctx context.Context, r *Renderer, n ast.Node) ast.WalkStatus

RendererFunc is a map of callbacks for handling each ast.Node.

type WYSIWYG

type WYSIWYG struct {
	Buffer *gtk.TextBuffer
	Tags   *gtk.TextTagTable
	Source []byte

	Head *gtk.TextIter
	Tail *gtk.TextIter
	// contains filtered or unexported fields
}

wysiwyg is the What-You-See-Is-What-You-Get node walker/highlighter.

func NewWYSIWYG

func NewWYSIWYG(ctx context.Context, buffer *gtk.TextBuffer, opts WYSIWYGOpts) *WYSIWYG

NewWYSIWYG creates a new instance of WYSIWYG.

func (*WYSIWYG) BoundIsInvisible

func (w *WYSIWYG) BoundIsInvisible() bool

BoundIsInvisible returns true if the iterators are surrounding regions of texts that are invisible.

func (*WYSIWYG) MarkBounds

func (w *WYSIWYG) MarkBounds(i, j int, names ...string)

MarkBounds is like MarkText, except it takes custom bounds instead of ones from an ast.Node.

func (*WYSIWYG) MarkText

func (w *WYSIWYG) MarkText(n ast.Node, names ...string)

MarkText walks n's children and marks all its ast.Texts with the given tag.

func (*WYSIWYG) MarkTextFunc

func (w *WYSIWYG) MarkTextFunc(n ast.Node, names []string, f func(h, t *gtk.TextIter))

MarkTextFunc is similar to markText, except the caller has control over the head and tail iterators before the tags are applied. This is useful for block elements.

func (*WYSIWYG) MarkTextTags

func (w *WYSIWYG) MarkTextTags(n ast.Node, tags ...*gtk.TextTag)

MarkTextTags is the tag variant of markText.

func (*WYSIWYG) MarkTextTagsFunc

func (w *WYSIWYG) MarkTextTagsFunc(n ast.Node, tags []*gtk.TextTag, f func(h, t *gtk.TextIter))

MarkTextTagsFunc is the tag variant of markTextFunc.

func (*WYSIWYG) Render

func (w *WYSIWYG) Render()

Render renders the WYSIWYG content using the current content inside the buffer. The Head and Tail iterators are revalidated.

func (*WYSIWYG) SetIter

func (w *WYSIWYG) SetIter(iter *gtk.TextIter, byteOffset int)

SetIter sets the given iterator to the given byte offset. It is the most correct way to convert an ast.Node's position to the iterator's.

SetIter reimplements text/url.go's autolink.

type WYSIWYGOpts

type WYSIWYGOpts struct {
	// Walker is the callback that's called when the tree is walked if it isn't
	// nil. It's meant to be a simple way to extend the renderer.
	Walker func(*WYSIWYG, ast.Node) ast.WalkStatus
	// SkipHTML, if true, will not highlight HTML tags.
	SkipHTML bool
}

Jump to

Keyboard shortcuts

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