Documentation
¶
Overview ¶
Package editor is what an editor extension needs from go-slides, as plain data: a preview of the deck, its problems positioned on lines, and the completions and hovers for directives, kinds and template functions.
It is the logic of the VS Code extension (go-slides/vscode), which runs it compiled to WebAssembly and only translates its results into the editor's types. Every entry point takes a Request: the deck and the workspace files the editor has read. A build reads nothing else (see vfs.Map); the files it wanted and did not get come back in Missing, for the editor to read and ask again.
Index ¶
Constants ¶
const PreviewCSS = `#go-slides-preview{margin:0 auto}` +
`#go-slides-preview>svg[data-marpit-svg]{display:block;width:100%;height:auto;margin:0 0 1.5em;` +
`box-shadow:0 1px 4px rgba(0,0,0,.25)}`
PreviewCSS lays the slides out in the editor's preview: one under the other, full width, with a gap and a shadow.
Variables ¶
This section is empty.
Functions ¶
func Detect ¶
Detect reports whether a Markdown document is a deck to preview: its front matter sets slides: true, or marp: true when marp is set. The editor leaves marp: true to Marp for VS Code when that extension is installed, so that the two do not both render the same document. An HCL front matter (---hcl) says slides = true or marp = true.
Types ¶
type Diagnostic ¶
type Diagnostic struct {
// File is the path of the file the problem is in: the deck, or a file
// it reads (a kinds file, an included fragment, slides.hcl).
File string `json:"file"`
Line int `json:"line"`
Column int `json:"column"`
EndLine int `json:"endLine"`
EndColumn int `json:"endColumn"`
// Severity is "error" or "warning".
Severity string `json:"severity"`
Message string `json:"message"`
}
Diagnostic is a problem positioned in a file. Lines are 0-based and columns count UTF-16 code units, as editors (LSP, VS Code) do.
func Diagnose ¶
func Diagnose(err error, path, src string) []Diagnostic
Diagnose positions an error from a build of the deck at path, whose text is src. Each line of the message (errors.Join) is one diagnostic.
type Directive ¶
type Directive struct {
Name string `json:"name"`
// Scope is "global" (the whole deck), "local" (this slide and the
// following ones; "_name" for this slide only) or "deck" (a go-slides
// front-matter key that is not a Marp directive).
Scope string `json:"scope"`
// Doc is Markdown.
Doc string `json:"doc"`
// Values are the values the directive takes, when they are a short
// list.
Values []string `json:"values,omitempty"`
}
Directive describes a directive for completion and hover.
func Directives ¶
func Directives() []Directive
Directives returns every directive and go-slides front-matter key, in the order Marpit lists them, then kind, then the deck keys.
type Func ¶
type Func struct {
Name string `json:"name"`
Signature string `json:"signature"`
Doc string `json:"doc"`
}
Func describes a template function.
type Hover ¶
type Hover struct {
// Doc is Markdown.
Doc string `json:"doc"`
// The hovered word, on Line from Column to EndColumn (UTF-16).
Line int `json:"line"`
Column int `json:"column"`
EndColumn int `json:"endColumn"`
}
Hover is what to show over a position.
type Item ¶
type Item struct {
Label string `json:"label"`
// Kind is "directive", "value", "kind", "theme", "function" or
// "data".
Kind string `json:"kind"`
Detail string `json:"detail,omitempty"`
// Doc is Markdown.
Doc string `json:"doc,omitempty"`
// Insert is the text to insert when it differs from Label.
Insert string `json:"insert,omitempty"`
}
Item is a completion.
type KindInfo ¶
type KindInfo struct {
Name string `json:"name"`
Extends string `json:"extends,omitempty"`
// Directives are the resolved directives, in the order they are set.
Directives []KV `json:"directives"`
}
KindInfo is a kind and the directives it sets, extends resolved.
type Request ¶
type Request struct {
// Path is the deck's path; relative paths in the deck resolve from its
// directory.
Path string `json:"path"`
// Source is the deck's text, as the editor holds it (unsaved edits
// included).
Source string `json:"source"`
// Files are the workspace files the editor has read, by path.
Files map[string]string `json:"files,omitempty"`
// Dirs are directories the editor has listed, with the names in them;
// a subdirectory's name ends with "/". A listed file the editor has not
// read comes back in Missing if the build reads it.
Dirs map[string][]string `json:"dirs,omitempty"`
// HTML allows all raw HTML. The editor sets it only when the user asked
// for it and trusts the workspace; a configuration file's html: true is
// not enough, since the workspace wrote it.
HTML bool `json:"html,omitempty"`
// NoConfig ignores slides.yaml and slides.hcl.
NoConfig bool `json:"noConfig,omitempty"`
}
Request is a deck and what the editor knows around it.
type Result ¶
type Result struct {
// HTML is the preview's markup: the theme's style element and the
// slides, each an inline SVG that scales to the preview's width.
HTML string `json:"html"`
// Slides counts the slides.
Slides int `json:"slides"`
// Diagnostics are the deck's problems; an error leaves HTML empty.
Diagnostics []Diagnostic `json:"diagnostics"`
// Missing are the files the build wanted and the request did not hold.
Missing []string `json:"missing"`
}
Result is a preview.