contentrefs

package
v1.166.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package contentrefs reads what a document body says about references: the mcp:// URIs and mcp:asset:<id> references it names, which of those its asset does not declare, and which it uses as a link target (#1834, #1875).

It is a lexical reading of text and grants nothing. Declaring a reference, and serving one, belong to internal/portal/assetrefs; a managed script's export and an agent's save both read a body through this package, so the two report the same references in the same words.

Index

Constants

View Source
const UndeclaredConsequence = "they are served as written and resolve to nothing"

UndeclaredConsequence is what happens to references a body names and its asset does not declare, in the words every surface that reports them uses (a script's run log, a save's result): the serving rewrite leaves them as written, so whatever loads one gets nothing.

Variables

This section is empty.

Functions

func AssetID added in v1.166.0

func AssetID(ref string) (string, bool)

AssetID returns the asset id an mcp:asset:<id> reference names, without a fragment or query, and whether ref is one.

func IsDownloadAnchor added in v1.146.0

func IsDownloadAnchor(tag string) bool

IsDownloadAnchor reports whether an <a> or <area> tag, from its '<' to its '>', carries a download attribute: the reader saves what it names rather than following it.

func Linked

func Linked(body, contentType string) []string

Linked returns each distinct reference string a body uses as a link target, in the order they first appear: an <a> or <area> href in HTML, XHTML, JSX, SVG or the markup a Markdown document embeds, and a Markdown link or autolink. Any other content type has no links and returns nil.

A reference is served as the bytes of what it names, so it can be loaded (an <img src>, a stylesheet, a fetch) and it cannot be followed: the frame a document renders in blocks navigation, and a destination that is a file's raw bytes is not a page, so a write linking one is refused rather than stored as a link that goes nowhere (#1875). A Markdown image, ![alt](ref), loads its destination and is not a link, and neither is an anchor with a download attribute, which saves the file (#2127). An mcp:asset:<id> link target is a link between assets (#2432): LinkedAssets reads those and RefusedLinks the rest.

func LinkedAssets added in v1.166.0

func LinkedAssets(body, contentType string) []string

LinkedAssets returns the ids of the assets a body links to (#2432): each link target written as mcp:asset:<id>, in the order they first appear. A link between assets is a pointer: saving one grants nothing and checks nothing, and following it opens the target in the portal, whose own access check decides what the reader sees.

func Named

func Named(body string) []string

Named returns every distinct reference string a textual body names: each managed resource by its mcp:// URI, then each asset by its mcp:asset:<id> reference, both in the order they first appear.

It recognizes the default resource scheme only. A deployment that renamed its scheme (resources.managed.uri_scheme) writes URIs this does not see, so a caller must treat an empty result as "found none", never as "there are none". Declaration is unaffected: it is the Declarer's, which takes the deployment's scheme.

It is the reading the serving rewrite would need a declaration for, so a surface can tell an author which references in a document will be served as written and resolve to nothing (#1834, #1875). It grants nothing: a string found here is a string, and only a declaration makes it load.

func RefusedLinks(body, contentType string) []string

RefusedLinks returns the link targets a write is refused for: every one except an mcp:asset:<id> link, which #2432 made a link between assets. A managed resource (mcp://) or a form used as a link target still goes nowhere: its reference is served as bytes, not as a page.

func RewriteDownloadAnchors added in v1.146.0

func RewriteDownloadAnchors(body string, replace func(ref string) (string, bool)) string

RewriteDownloadAnchors returns body with the reference each download anchor names replaced by what replace returns for it, leaving every other anchor and every other occurrence of the reference as written. replace reports false for a reference it does not serve, which is left as written. It is what lets the serving rewrite give a download anchor a URL that serves the file as an attachment while an <img> naming the same file loads it.

func Undeclared

func Undeclared(body string, declared []string) []string

Undeclared returns the reference strings body names that declared does not list, in the order Named finds them. Each declared entry is trimmed first, as a declaration is recorded.

Types

This section is empty.

Jump to

Keyboard shortcuts

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