render

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HeadingSlugs

func HeadingSlugs(source string) map[string]bool

HeadingSlugs returns a map of slug -> true for all headings in the source. Duplicate headings get GitHub-style suffixes: "heading", "heading-1", "heading-2".

func RenderImageInline

func RenderImageInline(path string, protocol ImageProtocol, fsys ...afero.Fs) (string, error)

RenderImageInline outputs an image using the given terminal protocol. Only safe outside alt-screen (e.g., `fur cat`), NOT inside Bubble Tea. An optional afero.Fs can be provided; if nil, the OS filesystem is used.

func Slugify

func Slugify(s string) string

Slugify converts heading text to a URL-compatible anchor slug. Matches GitHub's heading anchor generation: lowercase, spaces to hyphens, strip non-alphanumeric except hyphens and underscores.

Types

type CodeRenderer

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

CodeRenderer provides syntax highlighting via Chroma.

func NewCodeRenderer

func NewCodeRenderer(theme string, terminal bool) *CodeRenderer

NewCodeRenderer creates a code renderer. Set terminal=true for TUI (terminal256) output, false for HTML output.

func (*CodeRenderer) CSS

func (r *CodeRenderer) CSS() (string, error)

CSS returns the Chroma CSS classes for the current theme (HTML mode only).

func (*CodeRenderer) GetLanguage

func (r *CodeRenderer) GetLanguage(filename string) string

GetLanguage detects the language for a filename. Returns an empty string if no language is detected.

func (*CodeRenderer) Highlight

func (r *CodeRenderer) Highlight(filename, source string) (string, error)

Highlight returns syntax-highlighted content for the given file.

func (*CodeRenderer) HighlightFile

func (r *CodeRenderer) HighlightFile(filePath string) (string, error)

HighlightFile reads a file and returns syntax-highlighted content.

func (*CodeRenderer) HighlightLines

func (r *CodeRenderer) HighlightLines(filename, source string, startLine, endLine int) (string, error)

HighlightLines highlights source with a specific line range emphasized. Lines outside startLine..endLine are rendered normally; lines within the range receive Chroma's highlight style.

func (*CodeRenderer) HighlightToWriter

func (r *CodeRenderer) HighlightToWriter(w io.Writer, filename, source string) error

HighlightToWriter writes syntax-highlighted content to a writer.

func (*CodeRenderer) ListLanguages

func (r *CodeRenderer) ListLanguages() []string

ListLanguages returns all supported language names.

func (*CodeRenderer) SetFs

func (r *CodeRenderer) SetFs(fs afero.Fs)

SetFs sets the filesystem for file operations.

func (*CodeRenderer) SetTheme

func (r *CodeRenderer) SetTheme(theme string)

SetTheme changes the highlighting theme at runtime.

type Heading

type Heading struct {
	Level int
	Text  string
	Line  int
}

Heading represents a markdown heading extracted from source.

func ExtractHeadings

func ExtractHeadings(source string) []Heading

ExtractHeadings returns all headings from markdown source.

type ImageProtocol

type ImageProtocol int

ImageProtocol identifies the terminal image protocol to use.

const (
	ImageProtocolNone ImageProtocol = iota
	ImageProtocolKitty
	ImageProtocolITerm2
)

func DetectImageProtocol

func DetectImageProtocol() ImageProtocol

DetectImageProtocol returns the best available terminal image protocol.

type Link struct {
	Text        string
	Destination string
	Line        int
}

Link represents a markdown link extracted from source.

func ExtractLinks(source string) []Link

ExtractLinks returns all links from markdown source.

type MarkdownRenderer

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

MarkdownRenderer wraps Glamour for TUI markdown rendering.

func NewMarkdownRenderer

func NewMarkdownRenderer(theme string, width int) (*MarkdownRenderer, error)

NewMarkdownRenderer creates a markdown renderer with the given theme and width.

func (*MarkdownRenderer) Render

func (r *MarkdownRenderer) Render(source string) (string, error)

Render converts markdown to styled terminal output. On error, returns the raw source as fallback.

func (*MarkdownRenderer) RenderFile

func (r *MarkdownRenderer) RenderFile(filePath string) (string, error)

RenderFile reads a file and renders its markdown content. On render error, returns the raw file content as fallback.

func (*MarkdownRenderer) SetFs

func (r *MarkdownRenderer) SetFs(fs afero.Fs)

SetFs sets the filesystem for file operations.

func (*MarkdownRenderer) SetWidth

func (r *MarkdownRenderer) SetWidth(width int) error

SetWidth updates the word wrap width and recreates the renderer.

Jump to

Keyboard shortcuts

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