view

package
v0.0.0-...-55b6186 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StripDataURIText

func StripDataURIText(s string) string

StripDataURIText replaces data URIs in raw markdown text with a placeholder. This is used to reduce the size of bug reports that contain large base64-encoded images.

func StripDataURIs

func StripDataURIs(doc ast.Node, source []byte)

StripDataURIs is a DocumentTransformer that removes nodes containing data: URIs. It handles RawHTML nodes (e.g. <img src="data:...">), Image and Link nodes with data: destinations, and LinkReferenceDefinition nodes with data: destinations.

Types

type DocumentTransformer

type DocumentTransformer func(doc ast.Node, source []byte)

DocumentTransformer is a function that transforms a parsed Markdown AST before rendering. It can be used to remove or modify nodes in the document.

type GoBackMsg

type GoBackMsg struct{}

GoBackMsg is sent when the user presses the back key and the internal backstack is empty. Embedders should handle this message to navigate to the previous page.

type KeyMap

type KeyMap struct {
	Up       key.Binding
	Down     key.Binding
	PageUp   key.Binding
	PageDown key.Binding

	GotoTop key.Binding
	GotoEnd key.Binding
	Home    key.Binding
	End     key.Binding

	Left  key.Binding
	Right key.Binding

	NextLink      key.Binding
	PrevLink      key.Binding
	NextCodeBlock key.Binding
	PrevCodeBlock key.Binding
	NextHeading   key.Binding
	PrevHeading   key.Binding

	DecreaseWidth key.Binding
	IncreaseWidth key.Binding

	FollowLink key.Binding
	GoBack     key.Binding

	CopySelection key.Binding

	CursorMode  key.Binding
	VisualMode  key.Binding
	WordForward key.Binding
	WordBack    key.Binding
	WordEnd     key.Binding
	LineStart   key.Binding
	LineEnd     key.Binding

	Search      key.Binding
	NextMatch   key.Binding
	PrevMatch   key.Binding
	ClearSearch key.Binding
}

KeyMap defines key bindings for the Model. Each field is a key.Binding that can be customized or disabled. Use SetEnabled to bulk-enable/disable all bindings for focus management.

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns a KeyMap with the default key bindings matching the original hardcoded keys. DecreaseWidth and IncreaseWidth are disabled by default since they are unusual for an embedded component.

func (KeyMap) FullHelp

func (km KeyMap) FullHelp() [][]key.Binding

FullHelp returns the full set of key bindings for the help view. Implements the help.KeyMap interface from charmbracelet/bubbles/help.

func (*KeyMap) SetEnabled

func (km *KeyMap) SetEnabled(enabled bool)

SetEnabled bulk-enables or disables all bindings in the KeyMap. This is the primary mechanism for focus management: disable the KeyMap when the Model does not have focus, re-enable when it regains focus.

func (KeyMap) ShortHelp

func (km KeyMap) ShortHelp() []key.Binding

ShortHelp returns a short list of key bindings for the help view. Implements the help.KeyMap interface from charmbracelet/bubbles/help.

type Model

type Model struct {
	// KeyMap defines the key bindings for this model. Customize individual
	// bindings or call KeyMap.SetEnabled(false) to disable all input.
	KeyMap KeyMap
	// contains filtered or unexported fields
}

Model is a bubbletea model that displays rendered Markdown content.

func NewModel

func NewModel(opts ...Option) Model

NewModel creates a new Model with the given options.

func (*Model) AtBottom

func (m *Model) AtBottom() bool

AtBottom reports whether the viewport is scrolled to the bottom.

func (*Model) AtTop

func (m *Model) AtTop() bool

AtTop reports whether the viewport is scrolled to the top.

func (*Model) Clear

func (m *Model) Clear()

Clear removes all text from the buffer and resets all document-dependent state including selections, the navigation backstack, and the span tree.

func (*Model) ClearStatusMessage

func (m *Model) ClearStatusMessage()

ClearStatusMessage clears the transient gutter status message.

func (*Model) ColumnOffset

func (m *Model) ColumnOffset() int

ColumnOffset returns the current horizontal scroll offset.

func (*Model) ContentWidth

func (m *Model) ContentWidth() int

ContentWidth returns the current content width setting. 0 means full viewport width.

func (*Model) CursorMode

func (m *Model) CursorMode() bool

CursorMode reports whether cursor positioning mode is active.

func (*Model) DecreaseContentWidth

func (m *Model) DecreaseContentWidth()

DecreaseContentWidth reduces the content width by 10 columns (minimum 40).

func (*Model) EffectiveWidth

func (m *Model) EffectiveWidth() int

EffectiveWidth returns the computed effective width used for rendering.

func (*Model) FocusedLinkDestination

func (m *Model) FocusedLinkDestination() string

FocusedLinkDestination returns the URL of the currently selected link, or "" if the selection is not a link.

func (m *Model) FollowLink() bool

FollowLink follows the currently selected internal anchor link. Returns true if navigation occurred (the link was an internal anchor).

func (*Model) GetMarkdown

func (m *Model) GetMarkdown() []byte

GetMarkdown returns the raw markdown bytes.

func (*Model) GetName

func (m *Model) GetName() string

GetName returns the document name.

func (*Model) GoBack

func (m *Model) GoBack() bool

GoBack returns to the previous selection from the backstack. Returns true if there was a previous selection to return to.

func (*Model) GotoBottom

func (m *Model) GotoBottom()

GotoBottom scrolls to the bottom of the document and resets horizontal scroll.

func (*Model) GotoTop

func (m *Model) GotoTop()

GotoTop scrolls to the top of the document and resets horizontal scroll.

func (*Model) Height

func (m *Model) Height() int

Height returns the current viewport height.

func (*Model) IncreaseContentWidth

func (m *Model) IncreaseContentWidth()

IncreaseContentWidth increases the content width by 10 columns. If the result would be within 10 of the viewport width, resets to 0 (full width).

func (Model) Init

func (m Model) Init() tea.Cmd

Init implements tea.Model.

func (*Model) LineOffset

func (m *Model) LineOffset() int

LineOffset returns the current vertical scroll offset (first visible line index).

func (*Model) PageDown

func (m *Model) PageDown()

PageDown scrolls down by one page.

func (*Model) PageUp

func (m *Model) PageUp()

PageUp scrolls up by one page.

func (*Model) ScrollDown

func (m *Model) ScrollDown(n int)

ScrollDown scrolls down by n lines.

func (*Model) ScrollLeft

func (m *Model) ScrollLeft(n int)

ScrollLeft scrolls left by n columns.

func (*Model) ScrollPercent

func (m *Model) ScrollPercent() float64

ScrollPercent returns the scroll position as a value between 0.0 and 1.0.

func (*Model) ScrollRight

func (m *Model) ScrollRight(n int)

ScrollRight scrolls right by n columns.

func (*Model) ScrollUp

func (m *Model) ScrollUp(n int)

ScrollUp scrolls up by n lines.

func (*Model) Searching

func (m *Model) Searching() bool

Searching returns true if the search input prompt is active.

func (*Model) SelectAnchor

func (m *Model) SelectAnchor(anchor string) bool

SelectAnchor selects the next node with the given anchor. For anchors defined by HTML anchor tags (<a id="...">), this navigates to the anchor node itself. For heading-derived anchors, it navigates to the heading.

func (*Model) SelectFirstVisible

func (m *Model) SelectFirstVisible(selector Selector) bool

SelectFirstVisible selects the first node within the viewport that matches the given selector.

func (*Model) SelectLastVisible

func (m *Model) SelectLastVisible(selector Selector) bool

SelectLastVisible selects the last node within the viewport that matches the given selector.

func (*Model) SelectNext

func (m *Model) SelectNext(selector Selector) bool

SelectNext selects the first node after the current selection that matches the given selector.

func (*Model) SelectPrevious

func (m *Model) SelectPrevious(selector Selector) bool

SelectPrevious selects the first node before the current selection that matches the given selector.

func (*Model) SelectSpan

func (m *Model) SelectSpan(span *renderer.NodeSpan, highlight bool)

SelectSpan selects the given node span.

func (*Model) Selection

func (m *Model) Selection() *renderer.NodeSpan

Selection returns the current selection span.

func (*Model) SetColumnOffset

func (m *Model) SetColumnOffset(n int)

SetColumnOffset sets the horizontal scroll offset.

func (*Model) SetContentWidth

func (m *Model) SetContentWidth(width int)

SetContentWidth sets the desired content width. 0 means use full viewport width.

func (*Model) SetGutter

func (m *Model) SetGutter(showGutter bool)

SetGutter sets whether to show the gutter with document name and position.

func (*Model) SetHeight

func (m *Model) SetHeight(height int)

SetHeight sets the height of the viewport.

func (*Model) SetLineOffset

func (m *Model) SetLineOffset(n int)

SetLineOffset sets the vertical scroll offset.

func (*Model) SetSize

func (m *Model) SetSize(width, height int)

SetSize sets the viewport dimensions.

func (*Model) SetStatusMessage

func (m *Model) SetStatusMessage(msg string)

SetStatusMessage sets a transient status message to display in the gutter.

func (*Model) SetText

func (m *Model) SetText(name, markdown string)

SetText sets the text of this view. Previously contained text will be removed. If name is empty, the name is inferred from the first heading in the document.

func (*Model) SetWidth

func (m *Model) SetWidth(width int)

SetWidth sets the width of the viewport.

func (*Model) SetWrap

func (m *Model) SetWrap(wrap bool)

SetWrap sets whether long lines should be wrapped.

func (*Model) TotalLineCount

func (m *Model) TotalLineCount() int

TotalLineCount returns the total number of rendered lines.

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update implements tea.Model.

func (Model) View

func (m Model) View() string

View implements tea.Model.

func (*Model) VisibleLineCount

func (m *Model) VisibleLineCount() int

VisibleLineCount returns the number of lines visible in the viewport.

func (*Model) VisualMode

func (m *Model) VisualMode() bool

VisualMode reports whether visual selection mode is active.

func (*Model) Width

func (m *Model) Width() int

Width returns the current viewport width.

type OpenLinkMsg

type OpenLinkMsg struct {
	URL string
}

OpenLinkMsg is sent when the user activates a link that is not an internal document anchor. Embedders should handle this message to open the link in a browser or otherwise.

type Option

type Option func(*Model)

Option configures a Model during construction.

func WithContentWidth

func WithContentWidth(width int) Option

WithContentWidth sets the desired content width. 0 means use full viewport width.

func WithDiagramRenderer

func WithDiagramRenderer(dr renderer.DiagramRenderer) Option

WithDiagramRenderer sets the diagram renderer used to convert diagram code blocks (e.g. mermaid) into rendered text.

func WithDocumentTransformer

func WithDocumentTransformer(t DocumentTransformer) Option

WithDocumentTransformer adds a document transformer that will be applied to the parsed AST before rendering.

func WithGutter

func WithGutter(showGutter bool) Option

WithGutter sets whether to show the gutter with document name and position.

func WithHeight

func WithHeight(height int) Option

WithHeight sets the viewport height.

func WithKeyMap

func WithKeyMap(keyMap KeyMap) Option

WithKeyMap sets the key bindings for the model.

func WithTheme

func WithTheme(theme *chroma.Style) Option

WithTheme sets the color theme for rendering.

func WithWidth

func WithWidth(width int) Option

WithWidth sets the viewport width.

func WithWrap

func WithWrap(wrap bool) Option

WithWrap sets whether long lines should be wrapped.

type Selector

type Selector func(n ast.Node) (highlight, ok bool)

Selector is a function that determines whether a node should be selected.

Jump to

Keyboard shortcuts

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