Documentation
¶
Overview ¶
Package document owns file families and their viewing behavior.
Index ¶
Constants ¶
const ( // SniffLength is the prefix inspected for binary content. SniffLength = 8000 // PreviewLimit is the largest file size that is previewed, formatted, or // highlighted. Larger files show escaped plain source. PreviewLimit = 4 << 20 // SearchLimit is the largest file size included in content search. SearchLimit = 8 << 20 // DisplayLimit is the largest text file read for display. Larger non-image // files show a "Too large to display" note. DisplayLimit = 32 << 20 )
const ( PreviewMarkdown = "markdown" PreviewImage = "image" )
Preview kinds rendered by the UI. Image previews use the file's raw bytes.
Variables ¶
var ErrNotFormattable = errors.New("file type is not formattable")
ErrNotFormattable is returned when formatting a family without a Formatter.
Functions ¶
func DisplayReadLimit ¶ added in v0.1.6
DisplayReadLimit is the largest file of a type read for display, or -1 for none: image previews use raw bytes, so they display at any size.
Types ¶
type Availability ¶ added in v0.1.6
type Availability struct {
// TooLarge files are not read; only a note is shown.
TooLarge bool
PreviewDisabled bool
HighlightDisabled bool
SearchExcluded bool
}
Availability is what the size and binary limits leave of a file's views.
type CodeHandler ¶
type CodeHandler struct {
Definition Type
}
CodeHandler is reusable for explicitly registered source languages and image families: source and no HTML preview.
func (CodeHandler) Type ¶
func (h CodeHandler) Type() Type
type Context ¶
Context supplies navigation policy without giving handlers filesystem access. Project scopes rewritten links to the current project; Supports reports whether a link target names an in-scope file.
type Family ¶ added in v0.1.6
type Family struct {
// contains filtered or unexported fields
}
Family is a registered handler with registry-derived capabilities.
func (Family) Format ¶ added in v0.1.6
Format formats a copy of source and returns the formatted text.
type FormattedCodeHandler ¶ added in v0.1.6
type FormattedCodeHandler struct {
CodeHandler
FormatSource func([]byte) ([]byte, error)
}
FormattedCodeHandler adds an on-demand, read-only formatted view to source. FormatSource receives a copy of the file bytes.
type Formatter ¶ added in v0.1.6
Formatter is an optional Handler capability for a read-only formatted view. Errors leave the source view available.
type Handler ¶
Handler owns presentation, never filesystem access. Content search reads original source, so handlers know nothing about it. Preview returns escaped HTML, or an error without making source unavailable. Handlers without an HTML preview return empty HTML.
func NewJavaScript ¶ added in v0.1.6
func NewJavaScript() Handler
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is immutable after construction. It decides how a file is shown, never which files are in scope.
func Builtins ¶
func Builtins() *Registry
Builtins is the explicit composition point for file families. Registration only decides presentation; files outside these families use the plain-text fallback. Each family's Language names a Highlights language explicitly, or "text" for none; the browser highlights Source and Format (decision 0029).
func NewRegistry ¶
NewRegistry composes a source-only fallback family for unregistered files with additional handlers.
func (*Registry) Lookup ¶
Lookup returns the family for a file: exact base name, then extension, then the fallback. Every file has a family.
type Type ¶
type Type struct {
ID string `json:"id"`
Label string `json:"label"`
Extensions []string `json:"extensions"`
Filenames []string `json:"filenames"`
Language string `json:"language"`
PreviewKind string `json:"previewKind"`
PreviewLabel string `json:"previewLabel"`
DefaultMode string `json:"defaultMode"`
Formattable bool `json:"formattable"`
}
Type describes a file family and the views the UI can offer. Source is always available. An empty PreviewKind means no preview; extensions include their leading dot; filenames are exact base names. Matching is case-insensitive. Formattable is derived by the registry from the Formatter capability; handlers leave it unset. Language-server capabilities are composed by web. Language is a Highlights language ID for browser highlighting ("text" for none).
func (Type) HasTextSource ¶ added in v0.1.6
HasTextSource reports whether files of this type have a text source view. Raster images (image previews without a language) are binary regardless of their bytes.