livepreview

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package livepreview works out what live preview shows (docs/design/app.md#live-preview, ADR-0039): which ranges of a note's source hide, and what stands in for the rest, on the lines no selection touches. It is plain Go over the text: the editor turns its pieces into MyGo's replacements and its blocks into MyGo's blocks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Kind BlockKind
	// Line is the line it goes with, from 0.
	Line int
	// Label names it for assistive technology.
	Label string
	// Source is a Rendered block's Markdown.
	Source string
	// Width is the width an image's alias asks for, 0 for its own.
	Width int
	// Language and Code are a CodeHeader's.
	Language, Code string
}

Block is something drawn between lines, or in place of the lines a piece hides from their start through a newline.

type BlockKind

type BlockKind uint8

BlockKind says what a Block draws.

const (
	// Rendered draws Source as the reading view would.
	Rendered BlockKind = iota
	// CodeHeader draws a fence's language and a Copy button.
	CodeHeader
)

The kinds of block.

type EmbedKind

type EmbedKind uint8

EmbedKind says what an embed's target draws as.

const (
	// NoEmbed leaves the embed's source as written.
	NoEmbed EmbedKind = iota
	// ImageEmbed draws an image, under its line or in place of it.
	ImageEmbed
	// NoteEmbed draws a note, when the embed is alone on its line.
	NoteEmbed
)

The kinds of embed.

type Kind

type Kind uint8

Kind says what a range of the source shows as.

const (
	// Hide shows nothing: a mark that goes off the selection's lines.
	Hide Kind = iota
	// Bullet is a list's dot.
	Bullet
	// Quote is a quote's bar.
	Quote
	// Task is a check box.
	Task
	// Rule is a horizontal rule.
	Rule
	// Link shows Label, which a click follows.
	Link
	// Tag shows Label, which a click searches for.
	Tag
	// Footnote shows Label, the reference's name, which a click jumps from.
	Footnote
	// Dim shows Label, a done task's text, dimmed.
	Dim
	// Math draws Label as TeX.
	Math
)

The kinds of piece.

type LineStyle

type LineStyle struct {
	Line, Heading int
	Done          bool
}

LineStyle draws a line no selection touches as a heading of its level, or as a completed task.

type Lines added in v0.6.0

type Lines struct{ First, Last int }

Lines are the lines First through Last, from 0.

type Options

type Options struct {
	// Revealed reports whether a selection touches a line, from 0: such a
	// line shows its source. Nil touches none.
	Revealed func(line int) bool
	// HideFront hides the frontmatter, the properties panel standing in.
	HideFront bool
	// Blocks draws callouts, tables and fences' headers as Blocks; without
	// it they keep their source.
	Blocks bool
	// Embed says what the target of an embed or image draws as; wikilink
	// says which it is. Nil, or without Blocks, none draw.
	Embed func(target string, wikilink bool) EmbedKind
}

Options say what Scan shows.

type Piece

type Piece struct {
	Start, End int
	Kind       Kind
	// Done is a Task's state.
	Done bool
	// Label is what a Link, Tag, Footnote or Dim shows.
	Label string
	// Target is the file a Link names, "" for one to the web.
	Target string
}

Piece shows bytes Start to End of the text as its Kind.

type Result

type Result struct {
	Styles []LineStyle
	// Code are the lines of code blocks, fenced (with their fences) or
	// indented, whether or not a selection touches them: live preview
	// draws them on the code color. They are in order and apart.
	Code []Lines
	// Pieces are sorted and apart.
	Pieces []Piece
	// Blocks are in the order of their lines.
	Blocks []Block
}

Result is what shows of a text.

type Scanner

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

Scanner keeps each line's shape and pieces, so that a keystroke reads again only the line it changed. Keep one per editor. It is not safe for concurrent use.

func (*Scanner) Pieces

func (s *Scanner) Pieces(text string, revealed func(line int) bool, hideFront bool) []Piece

Pieces lists what shows of text, sorted and apart, without blocks. revealed reports whether a selection touches a line, from 0: such a line shows its source. With hideFront the frontmatter hides, the properties panel standing in for it.

func (*Scanner) Scan

func (s *Scanner) Scan(text string, o Options) Result

Scan works out what shows of text.

Jump to

Keyboard shortcuts

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