markdown

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: LGPL-2.1 Imports: 10 Imported by: 0

Documentation

Overview

Package markdown provides MarkdownView — a read-only widget that renders a useful subset of CommonMark / GFM:

  • ATX headings (#..######) with optional trailing #'s stripped
  • Setext headings (text followed by === or ---)
  • Paragraph text with **bold**, __bold__, *italic*, _italic_, `inline code`, ~~strikethrough~~, [link text](url), !image(url), <https://autolink>, <user@email.autolink>, and backslash escapes (\* \_ \\ etc.)
  • Fenced code blocks (``` …) with optional language hint that is visually consumed (the fence lines themselves don't render)
  • Indented code blocks (4+ leading spaces or a leading tab)
  • Bullet lists with - / * / +
  • Numbered lists (1. 2. 3.)
  • Block quotes (> …, including the empty > line)
  • Horizontal rules (--- / *** / ___)
  • Tabs expanded to 4 spaces at line start

Inline markers are stripped from the visible output — "**bold**" renders as "bold" with the bold attribute, not the verbatim string.

Ported from MarkdownView.pas. The Pascal version uses a regex-driven pre-pass; this Go port is a hand-rolled line scanner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alignment

type Alignment int

Alignment is the column-alignment hint produced by table parsing.

const (
	AlignLeft Alignment = iota
	AlignCenter
	AlignRight
)

type MarkdownView

type MarkdownView struct {
	views.Base

	Top     int
	VScroll *views.ScrollBar
	// contains filtered or unexported fields
}

MarkdownView is the read-only renderer.

func New

func New(bounds geom.Rect, v *views.ScrollBar) *MarkdownView

New constructs a viewer.

func (*MarkdownView) Draw

func (m *MarkdownView) Draw()

Draw paints visible lines.

func (*MarkdownView) GetTypeID

func (m *MarkdownView) GetTypeID() string

GetTypeID for serial registry.

func (*MarkdownView) HandleEvent

func (m *MarkdownView) HandleEvent(ev *drivers.Event)

HandleEvent dispatches:

  • Mouse wheel: scroll
  • Mouse-down + drag: select text; on release copy to clipboard via OSC 52 (same path the terminal widget uses)
  • CmCopy: copy current selection
  • Ctrl+A: select all
  • Esc: clear selection
  • Arrows / PgUp / PgDn / Home / End: scroll

func (*MarkdownView) SetMarkdown

func (m *MarkdownView) SetMarkdown(md string)

SetMarkdown parses md and renders it into displayable lines.

Jump to

Keyboard shortcuts

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