paths

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package paths resolves mdoc's per-user directories.

User-authored files (themes, and any future hand-edited config) live under an XDG-style config directory — $XDG_CONFIG_HOME/mdoc when set, otherwise ~/.config/mdoc — on every platform. That's deliberately the same friendly ~/.config path everywhere rather than os.UserConfigDir's platform default (e.g. ~/Library/Application Support on macOS), since users have to drop theme files in by hand and navigating to Library isn't ergonomic.

Regeneratable downloads (the Chromium snapshot) are NOT here — they stay in the system cache dir; see internal/browser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns mdoc's user config directory: $XDG_CONFIG_HOME/mdoc when that env var is set, otherwise ~/.config/mdoc.

func Display

func Display(p string) string

Display formats a path for showing to the user: made absolute, then with the home directory collapsed to "~" (e.g. "~/Github/mdoc/doc.md"). Paths outside the home directory, or anything that can't be resolved, are returned as the best absolute form available. This is presentation only — never feed the result back into file operations.

func IncludesDir added in v0.2.2

func IncludesDir() (string, error)

IncludesDir returns the user-level includes directory, <ConfigDir>/includes. It holds reusable markdown partials referenced by bare or scoped `:::include` keys (the include analogue of ThemesDir).

func ScopedKeyToRelpath added in v0.2.2

func ScopedKeyToRelpath(value string) (string, error)

ScopedKeyToRelpath turns a "::"-scoped key into a relative filesystem path, e.g. "kilohertz::legal::contract" -> "kilohertz/legal/contract". It rejects malformed scopes — an empty segment (from a leading, trailing, or doubled "::") or a "." / ".." segment that would escape the config dir — so a bad key fails loudly instead of resolving somewhere surprising.

func ThemesDir

func ThemesDir() (string, error)

ThemesDir returns the user-level themes directory, <ConfigDir>/themes.

Types

type RefKind added in v0.2.2

type RefKind int

RefKind classifies how a theme/include reference string should be resolved. The three forms are mutually exclusive and decided by Classify.

const (
	// KindFlatKey is a bare word (e.g. "thesis"): a global asset looked up by
	// name in the relevant config dir (themes/ or includes/).
	KindFlatKey RefKind = iota
	// KindScopedKey contains "::" (e.g. "kilohertz::legal::contract"): a global
	// asset in a subdirectory of the config dir.
	KindScopedKey
	// KindPath is an explicit filesystem path (contains "/", a leading "." or
	// "~", is absolute, or carries a file extension): resolved relative to the
	// document, not the config dir.
	KindPath
)

func Classify added in v0.2.2

func Classify(value string) RefKind

Classify decides how a reference value is resolved. The "::" scope check comes first so a scoped key is never mistaken for anything else; otherwise any path sigil — a "/" separator, a leading "." or "~", an absolute path, or a file extension — marks a path, and a plain bare word is a flat global key. The file extension is what distinguishes a global key ("disclaimer") from a sibling file referenced by bare name ("chapter1.md"). This rule is shared by theme and include resolution so both behave identically.

Jump to

Keyboard shortcuts

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