glitz

package module
v0.0.0-...-6bd6ba7 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

README

#+TITLE: glitz

Render Org-mode documents as ANSI-styled terminal text.

Like [[https://github.com/charmbracelet/glamour][glamour]] but for org-mode

* Overview

~glitz~ is a go library that parses [[https://orgmode.org/][Org Mode]] 
markup and renders it as richly styled terminal output using ANSI escape codes. 

* Features

- Org-mode element support
  - headings, 
  - paragraphs
  - emphasis
  - (bold, italic, underline, strikethrough)
  - inline code
  - links
  - tables
  - ordered/unordered/descriptive lists
  - block quotes
  - drawers
  - footnotes
  - timestamps
  - horizontal rules
  - keywords
  - TODO/DONE
  - states
  - tags
  - priorities.
- Syntax highlighting via [[https://github.com/alecthomas/chroma][Chroma]]
  - Automatic formatter selection based on terminal color
    profile (truecolor, 256-color, or basic ANSI).
- Dark and light themes :: built-in Dracula-inspired dark theme and a
  light theme, plus =auto= detection of terminal background.
- Word wrapping :: configurable column width with indent-aware
  wrapping via [[https://github.com/muesli/reflow][reflow]].
- Styled with lipgloss :: all element styles are defined as
  [[https://github.com/charmbracelet/lipgloss][lipgloss]] styles and can be customized.

* Installation

#+begin_src sh
go get codeberg.org/hoanga/glitz
#+end_src

* Usage

#+begin_src go
package main

import (
	"fmt"
	"strings"

	"codeberg.org/hoanga/glitz"
)

func main() {
	input := `* Hello World
This is *bold*, /italic/, and ~code~.`

	out, err := glitz.RenderString(input, glitz.RenderOptions{
		Width: 80,
		Style: "auto",
	})
	if err != nil {
		panic(err)
	}
	fmt.Print(out)
}
#+end_src

** RenderOptions

| Field              | Type     | Description                          |
|--------------------+----------+--------------------------------------|
| =Width=            | =int=    | Word-wrap column; 0 disables wrap    |
| =Style=            | =string= | ="dark"=, ="light"=, or ="auto"=     |
| =PreserveNewLines= | =bool=   | Preserve explicit newlines in output |

* License

See =LICENSE= file.

* Notes

An LLM (Claude) was used for the initial versions of this code

Documentation

Overview

Package glitz renders Org-mode documents as ANSI-styled terminal text.

It wraps the github.com/niklasfasching/go-org/org parser and provides a TermWriter that implements the org.Writer interface, producing styled plaintext output instead of HTML.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(input io.Reader, opts RenderOptions) (string, error)

Render parses Org-mode content and renders it as ANSI-styled terminal text.

func RenderString

func RenderString(content string, opts RenderOptions) (string, error)

RenderString is a convenience wrapper for string input.

Types

type RenderOptions

type RenderOptions struct {
	Width            int    // word-wrap column; 0 = no wrap
	Style            string // "dark", "light", "auto"
	PreserveNewLines bool
}

RenderOptions configures terminal rendering behavior.

type TermStyle

type TermStyle struct {
	Heading1      lipgloss.Style
	Heading2      lipgloss.Style
	Heading3      lipgloss.Style
	Heading4      lipgloss.Style
	Heading5      lipgloss.Style
	Heading6      lipgloss.Style
	Paragraph     lipgloss.Style
	CodeBlock     lipgloss.Style
	InlineCode    lipgloss.Style
	Bold          lipgloss.Style
	Italic        lipgloss.Style
	Underline     lipgloss.Style
	Strikethrough lipgloss.Style
	Link          lipgloss.Style
	LinkURL       lipgloss.Style
	BlockQuote    lipgloss.Style
	ListBullet    lipgloss.Style
	ListNumber    lipgloss.Style
	HRule         lipgloss.Style
	Table         lipgloss.Style
	TableHeader   lipgloss.Style
	TableBorder   lipgloss.Style
	Keyword       lipgloss.Style
	Drawer        lipgloss.Style
	Timestamp     lipgloss.Style
	Footnote      lipgloss.Style
	Todo          lipgloss.Style
	Done          lipgloss.Style
	Tag           lipgloss.Style
	Priority      lipgloss.Style
}

TermStyle defines the visual styling for each Org-mode element when rendered to the terminal.

func DarkStyle

func DarkStyle() TermStyle

DarkStyle returns a style preset for dark terminal backgrounds.

func LightStyle

func LightStyle() TermStyle

LightStyle returns a style preset for light terminal backgrounds.

type TermWriter

type TermWriter struct {
	strings.Builder
	// contains filtered or unexported fields
}

TermWriter implements org.Writer for ANSI-styled terminal output. It walks the Org-mode AST produced by go-org and emits styled plaintext instead of HTML.

func NewTermWriter

func NewTermWriter(opts RenderOptions) *TermWriter

NewTermWriter creates a TermWriter configured with the given options.

func (*TermWriter) After

func (w *TermWriter) After(d *org.Document)

func (*TermWriter) Before

func (w *TermWriter) Before(d *org.Document)

func (*TermWriter) WriteBlock

func (w *TermWriter) WriteBlock(b org.Block)

func (*TermWriter) WriteComment

func (w *TermWriter) WriteComment(c org.Comment)

func (*TermWriter) WriteDescriptiveListItem

func (w *TermWriter) WriteDescriptiveListItem(di org.DescriptiveListItem)

func (*TermWriter) WriteDrawer

func (w *TermWriter) WriteDrawer(d org.Drawer)

func (*TermWriter) WriteEmphasis

func (w *TermWriter) WriteEmphasis(e org.Emphasis)

func (*TermWriter) WriteExample

func (w *TermWriter) WriteExample(e org.Example)

func (*TermWriter) WriteExplicitLineBreak

func (w *TermWriter) WriteExplicitLineBreak(lb org.ExplicitLineBreak)

func (*TermWriter) WriteFootnoteDefinition

func (w *TermWriter) WriteFootnoteDefinition(fd org.FootnoteDefinition)
func (w *TermWriter) WriteFootnoteLink(fl org.FootnoteLink)

func (*TermWriter) WriteHeadline

func (w *TermWriter) WriteHeadline(h org.Headline)

func (*TermWriter) WriteHorizontalRule

func (w *TermWriter) WriteHorizontalRule(hr org.HorizontalRule)

func (*TermWriter) WriteInclude

func (w *TermWriter) WriteInclude(i org.Include)

func (*TermWriter) WriteInlineBlock

func (w *TermWriter) WriteInlineBlock(ib org.InlineBlock)

func (*TermWriter) WriteKeyword

func (w *TermWriter) WriteKeyword(kw org.Keyword)

func (*TermWriter) WriteLatexBlock

func (w *TermWriter) WriteLatexBlock(lb org.LatexBlock)

func (*TermWriter) WriteLatexFragment

func (w *TermWriter) WriteLatexFragment(lf org.LatexFragment)

func (*TermWriter) WriteLineBreak

func (w *TermWriter) WriteLineBreak(lb org.LineBreak)

func (*TermWriter) WriteList

func (w *TermWriter) WriteList(l org.List)

func (*TermWriter) WriteListItem

func (w *TermWriter) WriteListItem(li org.ListItem)

func (*TermWriter) WriteMacro

func (w *TermWriter) WriteMacro(m org.Macro)

func (*TermWriter) WriteNodeWithMeta

func (w *TermWriter) WriteNodeWithMeta(n org.NodeWithMeta)

func (*TermWriter) WriteNodeWithName

func (w *TermWriter) WriteNodeWithName(n org.NodeWithName)

func (*TermWriter) WriteNodesAsString

func (w *TermWriter) WriteNodesAsString(nodes ...org.Node) string

func (*TermWriter) WriteParagraph

func (w *TermWriter) WriteParagraph(p org.Paragraph)

func (*TermWriter) WritePropertyDrawer

func (w *TermWriter) WritePropertyDrawer(d org.PropertyDrawer)
func (w *TermWriter) WriteRegularLink(rl org.RegularLink)

func (*TermWriter) WriteResult

func (w *TermWriter) WriteResult(r org.Result)

func (*TermWriter) WriteStatisticToken

func (w *TermWriter) WriteStatisticToken(st org.StatisticToken)

func (*TermWriter) WriteTable

func (w *TermWriter) WriteTable(t org.Table)

func (*TermWriter) WriteText

func (w *TermWriter) WriteText(t org.Text)

func (*TermWriter) WriteTimestamp

func (w *TermWriter) WriteTimestamp(ts org.Timestamp)

func (*TermWriter) WriterWithExtensions

func (w *TermWriter) WriterWithExtensions() org.Writer

Jump to

Keyboard shortcuts

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