markdownviewer

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 5 Imported by: 0

README

Markdown Viewer

Small markdown subset rendered to a scrollable terminal block.

markdown-viewer preview

Install

glyph add markdown-viewer

This copies markdown-viewer.go (and its test file) into your repo at the path your glyph.json aliases declare. After install, the file is yours: edit it, refactor it, rename it. There is no markdown-viewer library to keep in sync.

Hello, world

package main

import (
	"fmt"

	markdownviewer "github.com/truffle-dev/glyph/components/markdown-viewer"
	"github.com/truffle-dev/glyph/components/theme"
)

func main() {
	md := markdownviewer.New(theme.Default).
		WithSize(80, 18).
		WithSource("# Hello

A *terminal* markdown viewer.")
	fmt.Println(md.View())
}

API surface

Package: markdownviewer

Types

  • Viewer

Functions and methods

  • New
  • WithSource
  • WithSize
  • Offset
  • Init
  • Update
  • View
  • TotalLines

Dependencies

  • glyph component theme (installed automatically)
  • github.com/charmbracelet/bubbletea@v1.3.10
  • github.com/charmbracelet/lipgloss@v1.1.0
  • github.com/muesli/reflow@v0.3.0

Notes

Pass WithSource to load a markdown string. The viewer renders only the visible window. Up/Down scrolls one line, PgUp/PgDn scrolls a window, Home/End jumps. Tables, images, and nested lists are deliberately out of scope; for those, edit renderLines.

See also

License

MIT, same as the rest of glyph.

Documentation

Overview

Package markdownviewer renders a small markdown subset to a styled terminal block with theme tokens. Headings, paragraphs, bullet lists, blockquotes, code blocks, inline code, bold, italic, links, and a horizontal rule. No tables, no nesting, no images.

The viewer is a Bubble Tea model with a scrollable viewport. Up/Down scroll one line. PgUp/PgDn scroll a window. Home/End jump.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Viewer

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

Viewer is a Bubble Tea model that renders a markdown string to a scrollable terminal block.

func New

func New(t theme.Theme) Viewer

New constructs a Viewer with the given theme. Source is empty.

func (Viewer) Init

func (v Viewer) Init() tea.Cmd

Init implements tea.Model.

func (Viewer) Offset

func (v Viewer) Offset() int

Offset returns the current scroll offset in lines from the top.

func (Viewer) Source added in v0.38.0

func (v Viewer) Source() string

Source returns the current markdown string. Used by nook's mdpreview pane to re-feed source after recreating the viewer with a new theme.

func (Viewer) TotalLines

func (v Viewer) TotalLines() int

TotalLines is the count of rendered (post-wrap) lines.

func (Viewer) Update

func (v Viewer) Update(msg tea.Msg) (Viewer, tea.Cmd)

Update handles scroll key events. Mouse wheel events are not handled.

func (Viewer) View

func (v Viewer) View() string

View renders the markdown source as a slice of `height` lines starting at `offset`. Trailing space is preserved so callers can compose the block with a border.

func (Viewer) WithSize

func (v Viewer) WithSize(w, h int) Viewer

WithSize sets the rendered width and visible-row height. Minimums are enforced so the layout never collapses.

func (Viewer) WithSource

func (v Viewer) WithSource(s string) Viewer

WithSource sets the markdown string. Offset resets to 0.

Jump to

Keyboard shortcuts

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