convert

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package convert provides utilities for migrating legacy cheat sheet formats (such as .navi) into the standard Markdown-based AST format used by cheatmd.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertCheat

func ConvertCheat(content string, filename string) (string, error)

ConvertCheat converts a cheat/cheat plain-text cheatsheet to CheatMD format.

func ConvertDirectory

func ConvertDirectory(format, inputDir, outputDir string) error

ConvertDirectory scans the input directory for legacy cheat sheet files matching the specified format (e.g., "navi") and converts them into standard cheatmd Markdown files in the output directory.

func ConvertFile

func ConvertFile(format, inputPath, outputPath string) error

ConvertFile converts a single file of the given format.

func ConvertNavi

func ConvertNavi(content string, filename string) (string, error)

ConvertNavi converts a single navi .cheat file with no cross-file context. `@extends` references that can't be resolved within this file fall back to inline bare vars.

func ConvertNaviDirectory

func ConvertNaviDirectory(inputDir, outputDir string) error

ConvertNaviDirectory walks every .cheat file in inputDir, parses them all into a shared NaviIndex (so @extends references can resolve across files), and writes one converted markdown file per source under outputDir.

func ConvertTldr

func ConvertTldr(content string, filename string) (string, error)

ConvertTldr converts a TLDR markdown cheatsheet to CheatMD format.

func SerializeNaviFile

func SerializeNaviFile(file *NaviFile, idx *NaviIndex) string

SerializeNaviFile renders a file as cheatmd markdown. Cheats are emitted in section order, and each section's export module follows its cheats so the reader can see definitions next to the cheats that use them.

Types

type CheatEntry

type CheatEntry struct {
	Desc    string
	Command string
}

CheatEntry is a single parsed entry from a cheat/cheat plain-text file.

type NaviCheat struct {
	Description string
	Command     string
	Tags        []string // tags of the section this cheat lives in
	Imports     []string
}

NaviCheat is a single parsed entry from a navi `.cheat` file. Imports holds the section-level `@ extends` tags inherited at parse time plus any cheat-level `@` lines added after the heading.

type NaviFile struct {
	Filename string
	Sections []*NaviSection
}

NaviFile is one parsed navi cheat file: an ordered list of sections.

func ParseNaviFile

func ParseNaviFile(content, filename string) *NaviFile

ParseNaviFile parses a navi file into a NaviFile with per-section structure. Empty leading sections (no cheats, no vars) are dropped so they don't show up in the index as anonymous noise.

type NaviIndex struct {
	Files []*NaviFile
	ByTag map[string][]*NaviSection
}

NaviIndex resolves cross-file `@extends` references at section granularity. A single tag may appear under sections in many files, and `@tag` reaches every one of them.

func BuildNaviIndex

func BuildNaviIndex(files []*NaviFile) *NaviIndex

BuildNaviIndex registers every section under each of its tags so a cheat's `@extends` list can fan out to every matching section across the tree.

type NaviResult struct {
	Path    string
	Content string
}

NaviResult represents the intermediate parsing state of a single .navi file before it is serialized into the final cheatmd Markdown AST.

func ConvertNaviTree

func ConvertNaviTree(sources []NaviSource) []NaviResult

ConvertNaviTree converts every navi cheat file in a tree using a shared index, so `@extends` references can resolve var defs in sibling files.

type NaviSection struct {
	Tags     []string
	Imports  []string // section-level @extends (inherited by all cheats here)
	Vars     map[string]varDef
	VarOrder []string // declaration order, for deterministic module output
	Cheats   []NaviCheat
	// Module is the section's export name. Computed from the section's tag
	// list so multiple `% tag1, tag2` blocks in the same file produce
	// distinct module names instead of collapsing into a single file-wide
	// module.
	Module string
}

NaviSection is a `% tags` scope: every cheat declared until the next `%` shares this section's Vars and contributes to its Module's export. Sections are the granularity at which `@extends` resolves — a cheat with `@tag` reaches sections (across any file) whose Tags list contains `tag`.

type NaviSource struct {
	Path    string
	Content string
}

NaviSource/NaviResult are the directory-mode I/O pair.

Jump to

Keyboard shortcuts

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