linkrender

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LinkKind

type LinkKind int

LinkKind classifies a Markdown link destination.

const (
	LinkExternal    LinkKind = iota // http://, https://, //, mailto:, tel:
	LinkRelative                    // ./ or ../
	LinkContentRoot                 // leading / (within collection)
	LinkAnchorOnly                  // starts with #
	LinkAmbiguous                   // bare name — rejected as ambiguous
	LinkSiteRoot                    // configured escape prefix (e.g. site:/x) — site-root, lane-free
)

type PageLookup

type PageLookup interface {
	LookupInLane(relPermalink, lang, version string) *engine.Page
}

PageLookup is the interface the resolver needs from PageIndex.

type ParsedDest

type ParsedDest struct {
	Kind     LinkKind
	Path     string // cleaned path, .md/.mdx extension stripped
	Fragment string // without '#'
	Query    string // without '?'
	Raw      string // original href as written
}

ParsedDest is a classified, cleaned link destination.

func ClassifyDest

func ClassifyDest(href string) ParsedDest

ClassifyDest parses a raw Markdown link destination into its parts and classifies it. Only links with .md/.mdx extensions are treated as source-file references that need resolution. Links without these extensions (already-resolved URL paths like /about/) pass through as external.

type Renderer

type Renderer struct {
	CurrentPage *engine.Page
	PageIndex   *content.PageIndex
	URLResolver *engine.URLResolver
	LinkGraph   *links.LinkGraph

	// Collections is the per-build collection registry, used to detect when a
	// link target lives in an unversioned collection (cross-dimension resolution).
	Collections map[string]*engine.Collection
	// SiteRootEscapePrefix is the configured prefix (e.g. "site:") that routes a
	// link to the site root, bypassing collection/lane logic. Empty disables it.
	SiteRootEscapePrefix string

	PendingAnchors []links.PendingAnchorCheck
}

Renderer is a Goldmark node renderer for ast.KindLink that resolves internal links through the page index and URL resolver. External links pass through.

The CurrentPage, PageIndex, and URLResolver fields are swapped before each page render (same pattern as imagerender.Renderer.Lookup).

func NewRenderer

func NewRenderer() *Renderer

NewRenderer creates a link renderer with no page context. Context must be set via SetPage before rendering.

func (*Renderer) DrainPendingAnchors

func (r *Renderer) DrainPendingAnchors() []links.PendingAnchorCheck

DrainPendingAnchors returns and clears collected anchor checks.

func (*Renderer) RegisterFuncs

func (r *Renderer) RegisterFuncs(reg gmrenderer.NodeRendererFuncRegisterer)

RegisterFuncs registers the renderer for ast.KindLink.

func (*Renderer) Reset

func (r *Renderer) Reset()

Reset clears accumulated state between page renders.

func (*Renderer) ResolveHref

func (r *Renderer) ResolveHref(href string) (resolvedURL string)

ResolveHref classifies, resolves, records in the link graph, and handles pending anchors for a given href. Returns the resolved URL. Card/button extension renderers call this to share the same resolution infrastructure.

func (*Renderer) SetPage

func (r *Renderer) SetPage(page *engine.Page)

SetPage sets the current page context for link resolution.

type ResolveContext

type ResolveContext struct {
	PageIndex   PageLookup
	URLResolver URLResolverFunc
	Collections map[string]*engine.Collection
}

ResolveContext carries the per-build dependencies the resolver needs. Collections is nil-safe: a nil map falls back to same-lane resolution (the current page's version), preserving behavior for callers that don't supply it.

type ResolveResult

type ResolveResult struct {
	URL             string // final resolved URL (empty if not found)
	TargetPermalink string // target page's Permalink (for anchor validation)
	Found           bool
}

ResolveResult holds the outcome of resolving an internal link.

func ResolveInternalLink(
	dest ParsedDest,
	currentPage *engine.Page,
	ctx ResolveContext,
) ResolveResult

ResolveInternalLink resolves a parsed destination in the current page's lane, returning the final URL via the URL resolver. External, anchor-only, and site-root links short-circuit without an index lookup.

type URLResolverFunc

type URLResolverFunc func(relPath, lang, version string) string

URLResolverFunc is the URL resolver signature needed by the link resolver.

Jump to

Keyboard shortcuts

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