block

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: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CodeBlockCSS = cssutil.Applier("md-codeblock", `
	.md-codeblock.frame {
		background-color: alpha(mix(@theme_bg_color, @theme_fg_color, 0.1), 0.5);
	}
	.md-codeblock scrollbar {
		background: none;
		border:     none;
	}
	.md-codeblock:active scrollbar {
		opacity: 0.2;
	}
	.md-codeblock:not(.md-codeblock-expanded) scrollbar {
		opacity: 0;
	}
	.md-codeblock-text {
		font-family: monospace;
		padding: 4px 6px;
		padding-bottom: 0px; /* bottom-margin */
	}
	.md-codeblock-actions > *:not(label) {
		background-color: alpha(@theme_bg_color, 0.35);
		opacity: 0.5;
		padding: 0px 6px;
		margin-top:    4px;
		margin-right:  4px;
		margin-bottom: 4px;
	}
	.md-codeblock-actions > *:not(label):hover,
	.md-codeblock-expanded .md-codeblock-actions > * {
		opacity: 1;
	}
	.md-codeblock-language {
		font-family: monospace;
		font-size: 0.9em;
		margin: 0px 6px;
		color: mix(@theme_bg_color, @theme_fg_color, 0.85);
	}
	/*
	 * ease-in-out-gradient -steps 5 -min 0.2 -max 0 
	 * ease-in-out-gradient -steps 5 -min 0 -max 75 -f $'%.2fpx\n'
	 */
	.md-codeblock-voverflow .md-codeblock-cover {
		background-image: linear-gradient(
			to top,
			alpha(@theme_bg_color, 0.25) 0.00px,
			alpha(@theme_bg_color, 0.24) 2.40px,
			alpha(@theme_bg_color, 0.19) 19.20px,
			alpha(@theme_bg_color, 0.06) 55.80px,
			alpha(@theme_bg_color, 0.01) 72.60px
		);
	}
`)

Functions

func NewDefaultTextView

func NewDefaultTextView(Buffer *gtk.TextBuffer) *gtk.TextView

NewDefaultTextView creates a new TextView that TextBlock uses.

Types

type Blockquote

type Blockquote struct {
	*gtk.Box
	State *ContainerState
}

Blockquote is a widget block that boxes another list of widget blocks. To use it, create a new Blockquote using NewBlockquote with the current ContainerState, then use Blockquote.State to walk further.

func NewBlockquote

func NewBlockquote(current *ContainerState) *Blockquote

NewBlockquote creates a new Blockquote.

type CodeBlock

type CodeBlock struct {
	*gtk.Overlay
	// contains filtered or unexported fields
}

CodeBlock is a widget containing a block of code.

func NewCodeBlock

func NewCodeBlock(state *ContainerState) *CodeBlock

NewCodeBlock creates a new CodeBlock.

func (*CodeBlock) Highlight

func (b *CodeBlock) Highlight(language string)

Highlight highlights the whole codeblock by the given language. Calling this method will always add the _nohyphens tag. If language is empty, then no highlighting is actually done.

func (*CodeBlock) TextBlock

func (b *CodeBlock) TextBlock() *TextBlock

TextBlock implements TextWidgetBlock.

type ContainerState

type ContainerState struct {
	*gtk.Box
	// Viewer is the top-level Markdown viewer. It is the same for all new
	// ContainerStates created underneath the same Viewer.
	Viewer *Viewer
	// contains filtered or unexported fields
}

ContainerState is the state of a single level of a Markdown node boxed inside a container of widgets.

func (*ContainerState) Append

func (s *ContainerState) Append(block WidgetBlock)

Append appends another block into the container state. The appended block is marked as the current block and will be returned by Current.

func (*ContainerState) Context

func (s *ContainerState) Context() context.Context

Context returns the Viewer's context.

func (*ContainerState) Current

func (s *ContainerState) Current() WidgetBlock

Current returns the current WidgetBlock instance.

func (*ContainerState) FinalizeBlock

func (s *ContainerState) FinalizeBlock()

FinalizeBlock finalizes the current block. Any later use of the state must create a new block.

func (*ContainerState) ForEach

func (s *ContainerState) ForEach(f func(WidgetBlock) bool)

ForEach iterates over the current-level containers until f returns true.

func (*ContainerState) Reset

func (s *ContainerState) Reset()

Reset clears the container state and removes all widgets from the parent box.

func (*ContainerState) TagTable

func (s *ContainerState) TagTable() *gtk.TextTagTable

TagTable returns the Viewer's TagTable.

func (*ContainerState) TextBlock

func (s *ContainerState) TextBlock() *TextBlock

TextBlock returns either the current widget if it's a Text widget (*TextBlock or TextWidgetBlock), or it creates a new *TextBlock.

func (*ContainerState) Walk

func (s *ContainerState) Walk(f func(WidgetBlock) bool)

Walk is like ForEach, except all ContainerWidgetBlocks are traversed recursively.

func (*ContainerState) WithParent

func (s *ContainerState) WithParent(parent *gtk.Box) *ContainerState

WithParent creates a new ContainerState with the given parent widget and a new list. The Viewer is retained.

type ContainerWidgetBlock

type ContainerWidgetBlock interface {
	WidgetBlock
	State() *ContainerState
}

ContainerWidgetBlock is a WidgetBlock that also embeds other WidgetBlocks. It should be implemented by embedding

type ListIndex

type ListIndex struct {
	// Level is the depth of the list the item is in.
	Level int
	// Index is the index of the list item.
	Index int
	// Unordered is true if the list is unordered.
	Unordered bool
}

ListIndex is a list item index.

type ListItemBlock

type ListItemBlock struct {
	*gtk.Box
	ListIndex ListIndex
	// contains filtered or unexported fields
}

ListItemBlock is a text block that contains a list item.

func NewListItemBlock

func NewListItemBlock(state *ContainerState, listIndex ListIndex) *ListItemBlock

NewListItemBlock creates a new ListItemBlock.

func (*ListItemBlock) TextBlock

func (b *ListItemBlock) TextBlock() *TextBlock

TextBlock returns the underlying TextBlock.

type SeparatorBlock

type SeparatorBlock struct {
	*gtk.Separator
}

SeparatorBlock is a horizontal line block.

func NewSeparatorBlock

func NewSeparatorBlock() *SeparatorBlock

NewSeparatorBlock creates a new SeparatorBlock.

type TextBlock

type TextBlock struct {
	*gtk.TextView
	// Iter is the text block's internal iterator. Use this while walking to
	// insert texts. All methods that act on the block will also use this
	// iterator.
	Iter *gtk.TextIter
	// Buffer is the TextView's TextBuffer.
	Buffer *gtk.TextBuffer
	// contains filtered or unexported fields
}

func NewTextBlock

func NewTextBlock(state *ContainerState) *TextBlock

NewTextBlock creates a new TextBlock.

func NewTextBlockFromView

func NewTextBlockFromView(view *gtk.TextView, state *ContainerState) *TextBlock

NewTextBlockFromView creates a new TextBlock from the given TextView.

func (b *TextBlock) ApplyLink(url string, start, end *gtk.TextIter)

ApplyLink applies tags denoting a hyperlink.

func (*TextBlock) ConnectLinkHandler

func (b *TextBlock) ConnectLinkHandler()

ConnectLinkHandler connects the hyperlink handler into the TextBlock. Call this method if the TextBlock has a link. Only the first call will bind the handler.

func (*TextBlock) EmptyTag

func (b *TextBlock) EmptyTag(tagName string) *gtk.TextTag

EmptyTag gets an existing tag or creates a new empty one with the given name.

func (*TextBlock) EndLine

func (b *TextBlock) EndLine(amount int)

EndLine ensures that the given amount of new lines will be put before the iterator. It accounts for existing new lines in the Bufferfer.

func (*TextBlock) Insert

func (b *TextBlock) Insert(text string)

Insert inserts text into the buffer at the current iterator position.

func (*TextBlock) InsertNewLines

func (b *TextBlock) InsertNewLines(n int)

InsertNewLines inserts n new lines without checking for existing new lines. Most users should use EndLine instead. If n < 1, then no insertion is done.

func (*TextBlock) IsNewLine

func (b *TextBlock) IsNewLine() bool

IsNewLine returns true if the iterator is currently on a new line.

func (*TextBlock) Tag

func (b *TextBlock) Tag(tagName string) *gtk.TextTag

Tag returns a tag from the md.Tags table. One is added if it's not already in the shared TagsTable.

func (*TextBlock) TagBounded

func (b *TextBlock) TagBounded(tag *gtk.TextTag, f func())

TagBounded saves the current offset and calls f, expecting the function to use s.iter. Then, the tag with the given name is applied on top.

func (*TextBlock) TagNameBounded

func (b *TextBlock) TagNameBounded(tagName string, f func())

TagNameBounded wraps around TagBounded and HTMLTag.

func (*TextBlock) TextBlock

func (b *TextBlock) TextBlock() *TextBlock

TextBlock returns itself. It impleemnts the TextWidgetChild interface.

func (*TextBlock) TrailingNewLines

func (b *TextBlock) TrailingNewLines() int

TrailingNewLines counts the number of trailing new lines up to 2.

type TextWidgetBlock

type TextWidgetBlock interface {
	WidgetBlock
	TextBlock() *TextBlock
}

TextWidgetBlock is a WidgetBlock that also embeds a TextBlock. All children that has appendable texts should implement this.

type Viewer

type Viewer struct {
	*gtk.Box
	// contains filtered or unexported fields
}

Viewer is a widget that renders a Markdown AST node into widgets. All widgets within the viewer are strictly immutable. A Viewer itself is a ContainerWidgetBlock.

func NewViewer

func NewViewer(ctx context.Context) *Viewer

NewViewer creates a new Markdown viewer.

func (*Viewer) SetExtraMenu

func (v *Viewer) SetExtraMenu(model gio.MenuModeller)

SetExtraMenu sets the given menu for all children widget nodes.

func (*Viewer) State

func (v *Viewer) State() *ContainerState

State returns the Viewer's ContainerState. It implements ContainerWidgetBlock.

func (*Viewer) TagTable

func (v *Viewer) TagTable() *gtk.TextTagTable

TagTable returns the viewer's shared TextTagTable.

type WidgetBlock

type WidgetBlock interface {
	gtk.Widgetter
}

WidgetBlock describes the minimum interface of a child within the widget tree.

Jump to

Keyboard shortcuts

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