schema

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDefaultFile

func CreateDefaultFile(path string) error

CreateDefaultFile creates a .mdschema.yml file with default configuration demonstrating all available schema capabilities.

func FindSchema

func FindSchema(startPath string) (string, error)

FindSchema discovers schema files in the directory hierarchy

Types

type CodeBlockRule

type CodeBlockRule struct {
	Lang string `yaml:"lang,omitempty" json:"lang,omitempty" lc:"language identifier (bash, go, python, etc.) - omit for any language"`
	Min  int    `yaml:"min,omitempty" json:"min,omitempty" lc:"minimum required blocks"`
	Max  int    `yaml:"max,omitempty" json:"max,omitempty" lc:"maximum allowed blocks"`
}

CodeBlockRule defines validation for code blocks within a section

type CountConstraint added in v0.9.0

type CountConstraint struct {
	Min int `yaml:"min,omitempty" json:"min,omitempty" lc:"minimum occurrences required"`
	Max int `yaml:"max,omitempty" json:"max,omitempty" lc:"maximum occurrences allowed (0 = unlimited)"`
}

CountConstraint defines how many times a structure element can match

type FieldFormat added in v0.4.0

type FieldFormat string

FieldFormat represents the format of a frontmatter field

const (
	FieldFormatDate  FieldFormat = "date"  // YYYY-MM-DD
	FieldFormatEmail FieldFormat = "email" // valid email address
	FieldFormatURL   FieldFormat = "url"   // http:// or https://
)

Field format constants for frontmatter validation

func (FieldFormat) JSONSchema added in v0.5.0

func (FieldFormat) JSONSchema() *jsonschema.Schema

JSONSchema implements jsonschema.JSONSchemer to add enum constraint

type FieldType added in v0.4.0

type FieldType string

FieldType represents the type of a frontmatter field

const (
	FieldTypeString  FieldType = "string"
	FieldTypeNumber  FieldType = "number"
	FieldTypeBoolean FieldType = "boolean"
	FieldTypeArray   FieldType = "array"
	FieldTypeDate    FieldType = "date"
)

Field type constants for frontmatter validation

func (FieldType) JSONSchema added in v0.5.0

func (FieldType) JSONSchema() *jsonschema.Schema

JSONSchema implements jsonschema.JSONSchemer to add enum constraint

type ForbiddenTextPattern added in v0.4.0

type ForbiddenTextPattern struct {
	// Literal is set when using scalar form (e.g., forbidden_text: "TODO") - substring match
	Literal string `yaml:"-" json:"-"`

	// Pattern is the regex pattern to match (always treated as regex)
	Pattern string `yaml:"pattern,omitempty" json:"pattern,omitempty" lc:"regex pattern that must NOT appear"`
}

ForbiddenTextPattern defines a text pattern that must NOT appear

func (ForbiddenTextPattern) JSONSchema added in v0.5.0

func (ForbiddenTextPattern) JSONSchema() *jsonschema.Schema

JSONSchema implements jsonschema.JSONSchemer for union type support (string | object)

func (*ForbiddenTextPattern) UnmarshalYAML added in v0.4.0

func (f *ForbiddenTextPattern) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements custom unmarshaling to support both string and object syntax

type FrontmatterConfig added in v0.4.0

type FrontmatterConfig struct {
	// Optional indicates frontmatter block is not required (default: false = required)
	Optional bool `yaml:"optional,omitempty" json:"optional,omitempty" lc:"frontmatter block is not required"`

	// Fields defines the required/optional fields and their constraints
	Fields []FrontmatterField `yaml:"fields,omitempty" json:"fields,omitempty" lc:"field definitions"`
}

FrontmatterConfig defines validation rules for YAML frontmatter

type FrontmatterField added in v0.4.0

type FrontmatterField struct {
	// Name is the field name (required)
	Name string `yaml:"name" json:"name" lc:"field name"`

	// Optional indicates whether this field is not required (default: false = required)
	Optional bool `yaml:"optional,omitempty" json:"optional,omitempty" lc:"field is not required"`

	// Type is the expected type (use FieldType* constants)
	Type FieldType `yaml:"type,omitempty" json:"type,omitempty" lc:"string, number, boolean, array, date"`

	// Format specifies format validation (use FieldFormat* constants)
	Format FieldFormat `yaml:"format,omitempty" json:"format,omitempty" lc:"date, email, or url"`
}

FrontmatterField defines a single frontmatter field requirement

type HeadingPattern added in v0.3.0

type HeadingPattern struct {
	// Literal is set when using scalar form (e.g., heading: "## Features") - exact match
	Literal string `yaml:"-" json:"-"`

	// Pattern is the heading regex pattern to match (always treated as regex)
	Pattern string `yaml:"pattern,omitempty" json:"pattern,omitempty" lc:"heading regex pattern"`

	// Expr is a boolean expression for dynamic matching (e.g., "slug(filename) == slug(heading)")
	// Available variables: filename (without extension), heading (heading text)
	// Available functions: slug, lower, upper, trim, hasPrefix, hasSuffix, strContains, match, replace, trimPrefix, trimSuffix
	Expr string `yaml:"expr,omitempty" json:"expr,omitempty" lc:"boolean expression for dynamic matching"`
}

HeadingPattern defines a heading pattern with optional regex or expression support

func (*HeadingPattern) GetReadableName added in v0.9.1

func (h *HeadingPattern) GetReadableName() string

GetReadableName returns a human-readable title for HeadingPattern

func (HeadingPattern) JSONSchema added in v0.5.0

func (HeadingPattern) JSONSchema() *jsonschema.Schema

JSONSchema implements jsonschema.JSONSchemer for union type support (string | object)

func (*HeadingPattern) UnmarshalYAML added in v0.3.0

func (h *HeadingPattern) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements custom unmarshaling to support both string and object syntax

type HeadingRules added in v0.4.0

type HeadingRules struct {
	// NoSkipLevels ensures heading levels are not skipped (e.g., h1 -> h3 without h2)
	NoSkipLevels bool `yaml:"no_skip_levels,omitempty" json:"no_skip_levels,omitempty" lc:"disallow skipping levels (e.g., h1 -> h3)"`

	// Unique ensures all headings in the document are unique
	Unique bool `yaml:"unique,omitempty" json:"unique,omitempty" lc:"all headings must be unique"`

	// UniquePerLevel ensures headings are unique within the same level
	UniquePerLevel bool `yaml:"unique_per_level,omitempty" json:"unique_per_level,omitempty" lc:"headings unique within same level"`

	// MaxDepth limits the maximum heading depth (1-6, where 1 is h1)
	MaxDepth int `yaml:"max_depth,omitempty" json:"max_depth,omitempty" lc:"maximum heading depth (1-6)"`
}

HeadingRules defines global validation rules for document headings

type ImageRule added in v0.4.0

type ImageRule struct {
	Min        int      `yaml:"min,omitempty" json:"min,omitempty" lc:"minimum required images"`
	Max        int      `yaml:"max,omitempty" json:"max,omitempty" lc:"maximum allowed images"`
	RequireAlt bool     `yaml:"require_alt,omitempty" json:"require_alt,omitempty" lc:"require alt text"`
	Formats    []string `yaml:"formats,omitempty" json:"formats,omitempty" lc:"allowed formats (png, jpg, gif, etc.)"`
}

ImageRule defines validation for images within a section

type LinkRule added in v0.3.0

type LinkRule struct {
	// ValidateInternal validates anchor links (#section-name)
	ValidateInternal bool `yaml:"validate_internal,omitempty" json:"validate_internal,omitempty" lc:"check anchor links (#section-name)"`

	// ValidateFiles validates relative file links (./other.md)
	ValidateFiles bool `yaml:"validate_files,omitempty" json:"validate_files,omitempty" lc:"check relative file links (./other.md)"`

	// ValidateExternal validates external URLs (http/https)
	ValidateExternal bool `yaml:"validate_external,omitempty" json:"validate_external,omitempty" lc:"check external URLs (http/https)"`

	// ExternalTimeout is the timeout in seconds for external URL checks (default: 10)
	ExternalTimeout int `yaml:"external_timeout,omitempty" json:"external_timeout,omitempty" lc:"timeout in seconds for external URL checks"`

	// AllowedDomains restricts external links to these domains only
	AllowedDomains []string `yaml:"allowed_domains,omitempty" json:"allowed_domains,omitempty" lc:"restrict external links to these domains"`

	// BlockedDomains blocks external links to these domains
	BlockedDomains []string `yaml:"blocked_domains,omitempty" json:"blocked_domains,omitempty" lc:"block links to these domains"`
}

LinkRule defines validation rules for links in the document

type ListRule added in v0.4.0

type ListRule struct {
	Min      int      `yaml:"min,omitempty" json:"min,omitempty" lc:"minimum required lists"`
	Max      int      `yaml:"max,omitempty" json:"max,omitempty" lc:"maximum allowed lists"`
	Type     ListType `yaml:"type,omitempty" json:"type,omitempty" lc:"ordered, unordered, or empty for any"`
	MinItems int      `yaml:"min_items,omitempty" json:"min_items,omitempty" lc:"minimum items per list"`
}

ListRule defines validation for lists within a section

type ListType added in v0.4.0

type ListType string

ListType represents the type of a list

const (
	ListTypeOrdered   ListType = "ordered"
	ListTypeUnordered ListType = "unordered"
)

List type constants

func (ListType) JSONSchema added in v0.5.0

func (ListType) JSONSchema() *jsonschema.Schema

JSONSchema implements jsonschema.JSONSchemer to add enum constraint

type RequiredTextPattern added in v0.3.0

type RequiredTextPattern struct {
	// Literal is set when using scalar form (e.g., required_text: "text") - substring match
	Literal string `yaml:"-" json:"-"`

	// Pattern is the regex pattern to match (always treated as regex)
	Pattern string `yaml:"pattern,omitempty" json:"pattern,omitempty" lc:"regex pattern to match"`
}

RequiredTextPattern defines a required text pattern with optional regex support

func (RequiredTextPattern) JSONSchema added in v0.5.0

func (RequiredTextPattern) JSONSchema() *jsonschema.Schema

JSONSchema implements jsonschema.JSONSchemer for union type support (string | object)

func (*RequiredTextPattern) UnmarshalYAML added in v0.3.0

func (r *RequiredTextPattern) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements custom unmarshaling to support both string and object syntax

type Schema

type Schema struct {
	// Document structure with embedded section rules
	Structure []StructureElement `` /* 139-byte string literal not displayed */

	// Global link validation rules
	Links *LinkRule `yaml:"links,omitempty" json:"links,omitempty" hc:"Global link validation settings"`

	// Global heading validation rules
	HeadingRules *HeadingRules `yaml:"heading_rules,omitempty" json:"heading_rules,omitempty" hc:"Global heading validation rules"`

	// Frontmatter validation rules
	Frontmatter *FrontmatterConfig `yaml:"frontmatter,omitempty" json:"frontmatter,omitempty" hc:"YAML frontmatter validation"`
}

Schema represents the validation rules for Markdown files (v0.1 DSL)

func Load

func Load(path string) (*Schema, error)

Load reads and parses a schema file

type SectionRules

type SectionRules struct {
	// Required text/substrings within the section
	RequiredText []RequiredTextPattern `yaml:"required_text,omitempty" json:"required_text,omitempty" lc:"text that must appear in this section"`

	// Forbidden text patterns that must NOT appear
	ForbiddenText []ForbiddenTextPattern `yaml:"forbidden_text,omitempty" json:"forbidden_text,omitempty" lc:"text that must NOT appear"`

	// Code block requirements within this section
	CodeBlocks []CodeBlockRule `yaml:"code_blocks,omitempty" json:"code_blocks,omitempty" lc:"code block requirements"`

	// Image requirements within this section
	Images []ImageRule `yaml:"images,omitempty" json:"images,omitempty" lc:"image requirements"`

	// Table requirements within this section
	Tables []TableRule `yaml:"tables,omitempty" json:"tables,omitempty" lc:"table requirements"`

	// List requirements within this section
	Lists []ListRule `yaml:"lists,omitempty" json:"lists,omitempty" lc:"list requirements"`

	// Word count requirements for the section
	WordCount *WordCountRule `yaml:"word_count,omitempty" json:"word_count,omitempty" lc:"word count constraints"`
}

SectionRules defines validation rules scoped to a specific heading/section

type StructureElement

type StructureElement struct {
	// Heading pattern (string or {pattern: "...", regex: true})
	Heading HeadingPattern `yaml:"heading,omitempty" json:"heading,omitempty"`

	// Description is guidance text shown in generated output as an HTML comment
	Description string `yaml:"description,omitempty" json:"description,omitempty" lc:"section description shown in generated output"`

	// Optional element flag
	Optional bool `yaml:"optional,omitempty" json:"optional,omitempty" lc:"section is not required"`

	// Count defines how many times this element can match (default: exactly once)
	// When specified, takes precedence over Optional
	Count *CountConstraint `yaml:"count,omitempty" json:"count,omitempty" lc:"occurrence constraints {min, max}"`

	// Severity level for violations (error, warning, info). Default: error
	Severity string `` /* 147-byte string literal not displayed */

	// AllowAdditional permits extra subsections not defined in children
	AllowAdditional bool `yaml:"allow_additional,omitempty" json:"allow_additional,omitempty" lc:"allow extra subsections not in schema"`

	// Hierarchical children elements
	Children []StructureElement `yaml:"children,omitempty" json:"children,omitempty" lc:"nested subsections"`

	// Embedded section rules for validation within this element's scope
	*SectionRules `yaml:",inline"`
}

StructureElement represents an element in the document structure Supports hierarchical structure with children and section-scoped rules

func (StructureElement) JSONSchema added in v0.5.0

func (StructureElement) JSONSchema() *jsonschema.Schema

JSONSchema implements jsonschema.JSONSchemer for union type support (string | object)

func (*StructureElement) UnmarshalYAML

func (se *StructureElement) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements custom unmarshaling to support the new hierarchical syntax

type TableRule added in v0.4.0

type TableRule struct {
	Min             int      `yaml:"min,omitempty" json:"min,omitempty" lc:"minimum required tables"`
	Max             int      `yaml:"max,omitempty" json:"max,omitempty" lc:"maximum allowed tables"`
	MinColumns      int      `yaml:"min_columns,omitempty" json:"min_columns,omitempty" lc:"minimum columns per table"`
	RequiredHeaders []string `yaml:"required_headers,omitempty" json:"required_headers,omitempty" lc:"headers that must exist"`
}

TableRule defines validation for tables within a section

type WordCountRule added in v0.4.0

type WordCountRule struct {
	Min int `yaml:"min,omitempty" json:"min,omitempty" lc:"minimum words"`
	Max int `yaml:"max,omitempty" json:"max,omitempty" lc:"maximum words"`
}

WordCountRule defines word count constraints for a section

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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