editor

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

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

View Source
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

View Source
var Codes = diag.Codes

Codes are the diagnostic codes, with what each means in English (the text a UI translates).

The codes are made where the errors are (package diag): go-slides' own errors carry them, and Diagnose reads them; nothing here guesses from the words of a message.

Functions

func Detect

func Detect(src string, marp bool) bool

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.

func HelpLanguages added in v0.16.0

func HelpLanguages() []string

HelpLanguages are the languages that have help registered.

func RegisterHelp added in v0.16.0

func RegisterHelp(lang string, docs map[string]string)

RegisterHelp gives the help of a language ("fr", "pt"): the base of a tag, lower-case. A second call for the same language adds to the first.

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"`
	// Code names the kind of problem, stable across releases and wording
	// (see Codes): the Message is the compiler's or the parser's, in English;
	// a UI that speaks another language explains the Code. "" when the
	// problem is none of those known.
	Code string `json:"code,omitempty"`
}

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.

func Funcs

func Funcs() []Func

Funcs returns the template functions.

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.

func HoverAt

func HoverAt(r Request, line, char int) *Hover

HoverAt returns the hover at a 0-based line and UTF-16 character, nil if there is nothing to say.

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.

func Complete

func Complete(r Request, line, char int) []Item

Complete returns the completions at a 0-based line and UTF-16 character.

type KV

type KV struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

KV is a directive and its value.

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.

func KindList

func KindList(k deck.Kinds) ([]KindInfo, error)

KindList lists kinds by name.

type Request

type Request struct {
	// Lang is the language the help is wanted in ("fr", "pt-BR"…): the help
	// of a directive or a template function comes from the catalogue
	// RegisterHelp gave for it, English when it has none. Diagnostics stay
	// in English; their Code is what a UI explains in its own language.
	Lang string `json:"lang,omitempty"`
	// 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"`
	// Head and SlideHTML are HTML in parts, for a preview that patches
	// itself slide by slide instead of replacing its document: HTML is
	// Head, then each of SlideHTML (one inline SVG a slide), then "</div>".
	// Neither is a copy (Head is a slice of HTML, SlideHTML the rendered
	// slides' own strings), and neither is serialised.
	Head      string   `json:"-"`
	SlideHTML []string `json:"-"`
	// 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.

func Render

func Render(r Request) Result

Render builds the deck's preview.

Jump to

Keyboard shortcuts

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