links

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 6 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 links models formal task links and finds and classifies links in task text. It is the Go counterpart of lib/tasks/links.rb.

Bodies increasingly carry references into other systems (Slack threads, Jira tickets, PRs, docs); this is the one place that knows how to spot a link and name the system it points into, so every surface (`show`, `links`, `open`, the TUI opener) agrees.

Two shapes are recognized, in this order:

[[url][label]] / [[url]]   org-mode links, the canonical form for notes
https://…                  bare URLs in prose

Only web URLs count: an org internal link ([[My Heading]], [[id:…]], [[file:…]]) is navigation within org, not a reference into another system, so it is not reported.

Index

Constants

View Source
const (
	MaxFormalLinks = 50
	MaxURLLength   = 2000
	MaxLabelLength = 200
)

Variables

This section is empty.

Functions

func Classify

func Classify(raw string, customSystems map[string]string) string

Classify names the system a URL points into: a custom `systems` row (host suffix; user intent wins), then a built-in row on host — and path, when the row has one — else the bare host itself, so unknown systems still group and list meaningfully, else "link" for something unparseable.

func Expand

func Expand(value, template string) string

Expand turns a shorthand token into its full URL via the configured template — `jira:OPS-1234` with `link.jira = https://…/browse/%s` becomes that URL. A template without %s is treated as a prefix.

func TrimSentenceTail added in v1.9.0

func TrimSentenceTail(value string) string

TrimSentenceTail peels off what belongs to the sentence rather than to a bare URL — trailing punctuation and unbalanced closers — exactly as Extract does when it finds a URL in prose. A caller lifting a URL out of human text stores what Extract would have found, so the two never disagree about where the URL ends.

func UnsafeFormalText added in v1.7.0

func UnsafeFormalText(value string) bool

UnsafeFormalText reports control or line-separator characters forbidden in either member of a stored link.

func ValidFormalLabel added in v1.7.0

func ValidFormalLabel(label string) bool

ValidFormalLabel reports whether a present stored label is canonical.

func ValidFormalURL added in v1.7.0

func ValidFormalURL(raw string) bool

ValidFormalURL reports whether a stored link is safe to expose to openers.

Types

type FormalLink struct {
	URL   string `json:"url"`
	Label string `json:"label,omitempty"`
}

FormalLink is one ordered, stored task link before system classification.

type Link struct {
	URL    string
	Label  *string
	System string
	Source Source
}

Link is one reference found in task text. Label is nil for a bare URL — an absent label and an empty one are different answers, and the JSON says so.

func Extract

func Extract(lines []string, shorthands, customSystems map[string]string) []Link

Extract returns every web link in `text`, in FILE ORDER (masking preserves string offsets, so the three passes interleave correctly — `open <n>` counts the same way the note reads), de-duplicated by URL.

Dedupe keeps the most useful spelling, not the earliest one: among the occurrences of one URL, the first LABELLED occurrence wins, and only if none is labelled does the first (bare) occurrence stand in. Which spelling survives is therefore independent of where in the text each one sits.

Position still decides ORDER: each surviving link is listed at its URL's FIRST occurrence, whichever spelling that was, so adding a label to a URL already in the text never moves anything in the listing.

`shorthands` (name => URL template with %s, from config `link.<name>` rows) additionally expands compact tokens like `jira:OPS-1234`. `customSystems` (name => host, from config `system.<name>` rows) extends classification for self-hosted instances the built-in registry cannot know.

type Source added in v1.7.0

type Source string

Source identifies which owned or derived task field contributed a link.

const (
	SourceFormal Source = "formal"
	SourceTitle  Source = "title"
	SourceBody   Source = "body"
)

Jump to

Keyboard shortcuts

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