export

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package export implements the source-to-source transform behind `mdsmith export`. It strips every directive start/end marker from a Markdown file while keeping the directive bodies as plain Markdown, so the result renders on any tool without mdsmith knowledge.

The package operates purely on an in-memory *lint.File. File reads and disk writes are the CLI layer's responsibility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Export

func Export(f *lint.File, mode Mode, rules []rule.Rule) ([]byte, []lint.Diagnostic)

Export returns a portable, directive-free copy of f's source.

rules carries the caller's effective ruleset (already cloned and configured via engine.ConfigureRule, and filtered to enabled rules only — like fix.Fixer.fixableRules). Staleness checks (Check mode) and regeneration (Fix mode) only consult rules in this slice, so a directive disabled in `.mdsmith.yml` neither produces a stale-body refusal nor gets regenerated on `--fix`.

Marker stripping is independent of `rules`: every directive registered in the global rule registry has its start/end markers stripped from the output, so a disabled directive's markers still disappear even though its body is untouched. Callers that want stripping but no staleness behavior can pass a nil rules slice.

Generated section markers are removed, generated bodies stay as plain Markdown, and `<?include?>` content is inlined (recursively, when the body is fresh or has been regenerated).

Exactly one of the returned values is populated:

  • on success, the exported bytes (non-nil) and a nil diagnostic slice — including the no-op case of a directive-free file
  • on Check-mode refusal, nil bytes and a non-empty diagnostic slice naming the offending directive(s); the caller should exit non-zero

Types

type Mode

type Mode int

Mode controls how Export handles directive staleness.

const (
	// Check is the default mode. A directive body that disagrees with
	// the engine's regenerated output is a refusal — Export returns nil
	// bytes and a diagnostic naming the stale directive.
	Check Mode = iota
	// Fix regenerates stale bodies in memory before stripping. The
	// source file is never written.
	Fix
	// NoCheck skips the staleness check entirely. Bodies are exported
	// exactly as they appear on disk.
	NoCheck
)

Jump to

Keyboard shortcuts

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