jsonhighlight

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package jsonhighlight tokenizes JSON for syntax highlighting.

It drives encoding/json/jsontext.Decoder once over the input, emitting one span per JSON token (string, number, literal, or structural delimiter) plus filler spans for inter-token bytes (commas, colons, whitespace). Object-key strings are distinguished from value strings via the decoder's stack-position state.

On parse error, spans for the prefix that decoded cleanly are returned; the unparsed remainder becomes a single CategoryPlain span. This mirrors gohighlight's degrade-gracefully approach so the editor never goes blank.

The output is a flat slice of byte-offset spans suitable for direct consumption by the codeview widget's retained CodeViewJob.Section calls. Output guarantees:

  • Every byte of src is covered by exactly one span.
  • For each span, src[Start:Stop] == Text and Stop-Start == len(Text).

Index

Constants

This section is empty.

Variables

View Source
var PackageProps = packageprops.Props{
	WASMWASI:         packageprops.WASMCompiles,
	WASMJS:           packageprops.WASMCompiles,
	WASMFreestanding: packageprops.WASMCompiles,
}

PackageProps records this package's curated properties (ADR-0080). Seeded by `boxer code analysis golang wasmsurvey props generate`; curate by hand. The same group's `props verify` reconciles it.

Functions

This section is empty.

Types

type CategoryE

type CategoryE int

CategoryE classifies a span for highlighting.

const (
	CategoryPlain       CategoryE = iota // unclassified bytes (parse-error remainder)
	CategoryPunctuation                  // { } [ ] , :
	CategoryKey                          // object-member name (the "name" of "name":value)
	CategoryStringLit                    // string value
	CategoryNumberLit                    // number value
	CategoryBoolLit                      // true / false
	CategoryNullLit                      // null
	CategoryWhitespace                   // gaps between tokens (spaces, tabs, newlines)
)

type Span

type Span struct {
	Start    int32
	Stop     int32
	Text     string
	Category CategoryE
}

Span represents a highlighted region of input source.

func Highlight

func Highlight(src string) (spans []Span)

Highlight tokenizes src and returns spans covering every byte exactly once. On parse error, the parsed prefix retains semantic categories and the unparseable tail is returned as a single CategoryPlain span.

Jump to

Keyboard shortcuts

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