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 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 ¶
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 pieces, so that a keystroke reads again only the line it changed. Keep one per editor. It is not safe for concurrent use.