contentlink

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package contentlink recognizes activatable references in rendered text.

Recognition is presentation-neutral and side-effect free. Callers provide ready resolver snapshots; unresolved candidates are returned as pending work for a later command rather than resolved during rendering.

Index

Constants

View Source
const (
	MaxNewDiffResolves         = 16
	MaxResourceLocatorChars    = 200
	MaxResourceMatchesPerLine  = 32
	MaxAutomaticMatchesPerLine = 64
	MaxRenderedRows            = 1000
	MaxRenderedColumns         = 4096
	MaxPendingResolutions      = 128
	MaxInternalURIBytes        = 2048
	MaxInternalNamespaceBytes  = 32
	MaxInternalIDRunes         = 512
	MaxInternalQueryParameters = 16
	MaxInternalQueryKeyBytes   = 32
	MaxInternalQueryValueRunes = 256
	MaxExplicitLabelColumns    = 4096
	// MaxExplicitDestinationBytes bounds a source-supplied OSC-8 URI before
	// contentlink retains it in a Span or resynthesizes it into rendered output.
	// The destination is zero-width terminal control data, so the rendered
	// column limit cannot bound it.
	MaxExplicitDestinationBytes = 2048
)

Variables

This section is empty.

Functions

func Activatable

func Activatable(k Kind) bool

Activatable reports whether hosts may bind and decorate the kind.

func Decorate

func Decorate(line string, spans []Span) string

Decorate underlines local references and synthesizes OSC-8 for safe HTTP(S) destinations: built-in URL spans, and resource spans whose locator is itself a browser URL — a claimed GitHub URL must keep its emulator hyperlink so cmd-click remains the escape hatch even after Sidecar reclassifies the span. Resource locators that are keys or refs stay underline-only.

Source OSC must first be removed by StripOSC8 or ScanFrame.

func IssueID

func IssueID(value string) bool

func NoteID added in v1.3.0

func NoteID(value string) bool

NoteID reports whether value is a td note identity (nt-…).

func SafeHTTPURL

func SafeHTTPURL(raw string) (string, bool)

SafeHTTPURL trims prose punctuation and accepts only http(s), with a host and no controls.

func SessionName

func SessionName(value string) bool

SessionName reports whether value is a Sidecar-owned attachable tmux session name. Stored notification targets use the same validation as scans.

func StripOSC8

func StripOSC8(line string) string

StripOSC8 strips every source OSC sequence. It fails closed if removal could leave a fresh introducer behind.

func WrapVisualRange

func WrapVisualRange(line string, startCol, endCol int, open, close string) string

Types

type DiffResolver

type DiffResolver func(raw string) (value string, extra Extra, ok bool)

type Extra

type Extra struct {
	Line      int
	Raw       string
	Provider  string
	Matcher   string
	Namespace string
}

Extra preserves the terminal-link scanner's original public shape while callers migrate to Ref. Raw is the token as rendered before ready resolution.

type FrameOptions

type FrameOptions struct {
	Ready              ResolutionSnapshot
	Matchers           []ResourceMatcher
	InternalNamespaces map[string]URIOptions
	// AllowedKinds bounds the kinds returned, decorated, and queued for
	// resolution. Nil preserves the scanner's all-kinds default; a non-nil
	// empty set allows none. Explicit OSC labels still claim their cells when
	// their destination kind is excluded, so automatic matching cannot turn a
	// disallowed explicit destination into a different action.
	//
	// Claim interaction: URL yield runs before this filter, so a surface that
	// allows KindURL but not KindResource would drop claimed URLs entirely —
	// inert text where a browser link used to be. Every current scanning
	// surface advertises both kinds together (docview.ContentLinkKinds is the
	// shared set, pinned by test); a future surface wanting one without the
	// other must decide what claimed URLs should do first.
	AllowedKinds KindSet
	Decorate     bool
}

type FrameResult

type FrameResult struct {
	Output  string
	Spans   []Span
	Pending []Pending
}

func ScanFrame

func ScanFrame(frame string, opts FrameOptions) FrameResult

ScanFrame recognizes a bounded, already-rendered ANSI frame. Explicit OSC-8 spans are extracted first and beat automatic matches. File and diff matching consults only Ready; misses become bounded, deduplicated Pending work.

type InternalURI

type InternalURI struct {
	Ref   Ref
	Query url.Values
}

InternalURI carries the stable intent reference and handler-owned options. Query is copied and may be safely retained by a handler.

func ParseInternalURI

func ParseInternalURI(raw string) (InternalURI, error)

func ParseInternalURIWith

func ParseInternalURIWith(raw string, opts URIOptions) (InternalURI, error)

type Kind

type Kind string

Kind classifies an activatable reference.

const (
	KindURL      Kind = "url"
	KindFile     Kind = "file"
	KindIssue    Kind = "issue"
	KindDiff     Kind = "diff"
	KindResource Kind = "resource"
	KindInternal Kind = "internal"
	// KindSession identifies a Sidecar-owned tmux session that a host can
	// attach. Only names Sidecar itself mints are recognized from text.
	KindSession Kind = "session"
)

type KindSet

type KindSet map[Kind]struct{}

KindSet bounds the reference kinds a rendered surface allows the host to recognize. The zero value allows none.

func NewKindSet

func NewKindSet(kinds ...Kind) KindSet

NewKindSet constructs a set containing kinds.

func (KindSet) Allows

func (s KindSet) Allows(kind Kind) bool

Allows reports whether kind may be activated from the surface.

type Options

type Options struct {
	Resolve     Resolver
	ResolveDiff DiffResolver
	Matchers    []ResourceMatcher
}

type Pending

type Pending struct {
	Kind Kind
	Raw  string
}

Pending names side-effecting work a caller may run after rendering. Only file and diff candidates are produced. Raw is the exact rendered token.

type Ref

type Ref struct {
	Kind      Kind
	Value     string
	Line      int
	Provider  string
	Matcher   string
	Namespace string
}

Ref is the presentation-neutral identity produced by every recognition path. Line is 1-based and zero when absent. Provider and Matcher identify an external resource matcher. Namespace is set only for internal intents.

type ResolutionIndex

type ResolutionIndex struct {
	// contains filtered or unexported fields
}

ResolutionIndex is a bounded per-surface cache. Resolution work happens outside this type; Put applies its result on the update path, and Snapshot gives View a side-effect-free copy.

func NewResolutionIndex

func NewResolutionIndex(limit int) *ResolutionIndex

func (*ResolutionIndex) Put

func (i *ResolutionIndex) Put(candidate Pending, ref Ref, found bool) bool

func (*ResolutionIndex) Reset

func (i *ResolutionIndex) Reset()

func (*ResolutionIndex) Snapshot

func (i *ResolutionIndex) Snapshot() ResolutionSnapshot

type ResolutionSnapshot

type ResolutionSnapshot struct {
	// contains filtered or unexported fields
}

ResolutionSnapshot is an immutable ready-only view used during rendering. A missing key means unresolved, not a negative result.

func (ResolutionSnapshot) Lookup

func (s ResolutionSnapshot) Lookup(kind Kind, raw string) (ref Ref, found, ready bool)

type Resolver

type Resolver func(raw string) (value string, extra Extra, ok bool)

Resolver and DiffResolver are the legacy synchronous scanner hooks. New rendered surfaces should use ScanFrame with a ResolutionSnapshot instead.

type ResourceMatcher

type ResourceMatcher struct {
	Provider   string
	ID         string
	Re         *regexp.Regexp
	ClaimHosts []string
}

ResourceMatcher is one live external matcher. The whole match is the locator.

ClaimHosts carries the matcher's instance configuration: the lowercased hostnames whose built-in URL spans that instance may reclassify into resource spans. It is empty for an instance that claims nothing, and it never widens what Re itself matches — a URL is yielded only when its host is listed here AND Re matches the entire URL string. Built-in precedence is not inverted anywhere else.

type Span

type Span struct {
	Kind     Kind
	Row      int
	StartCol int
	EndCol   int
	Value    string
	Extra    Extra
	Explicit bool
}

Span is one non-overlapping reference in inclusive visual columns. Row is zero for a line scan and the zero-based rendered row for a frame scan.

func Scan

func Scan(line string, resolve Resolver, resolveDiff DiffResolver) []Span

func ScanWith

func ScanWith(line string, opts Options) []Span

ScanWith preserves the existing synchronous terminal scanner contract. Built-ins win in URL, path:line, file, issue, diff, resource order.

func SpanForRef

func SpanForRef(ref Ref) Span

SpanForRef constructs a coordinate-free span. It is useful at adapters that still consume the compatibility Span vocabulary.

func (Span) Ref

func (s Span) Ref() Ref

Ref returns the shared identity for this rendered span.

type Surface

type Surface struct {
	ID          string
	Rect        mouse.Rect
	WorkDir     string
	ProjectRoot string
	Kinds       KindSet
	ReadOnly    bool
}

Surface describes one exact, already-rendered text rectangle that a host may scan for content links. Rect uses plugin-local coordinates.

type URIOptions

type URIOptions struct {
	AllowedQuery map[string]struct{}
	// ValidateID applies namespace-owned identity rules after generic URI
	// decoding and bounds checks. A nil validator accepts any generic ID.
	ValidateID func(string) bool
}

URIOptions is the generic parser's query allowlist. The zero value accepts no query parameters. Namespace handlers choose their own bounded keys.

Jump to

Keyboard shortcuts

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