@weave-md/validate
v0.3.1-alpha.0
Published
Reference validation for Weave Markdown
Maintainers
Readme
@weave-md/validate
Format conformance validator for Weave Markdown - lightweight for editor/CI use.
What It Does
@weave-md/validate validates Weave Markdown documents against the format specification:
- Format conformance - Validates Weave extended syntax and structure
- Schema validation - Checks YAML frontmatter and block content schemas
- Extended block validation - Validates Weave code blocks with YAML content:
imageblocks (requiresfile, warns about missingalt, validateswidthoptions)galleryblocks (requiresfilesarray, warns about missingalt)audioblocks (requiresfile, validates booleanautoplay,controls,loop)videoblocks (requiresfile, validatesstartnumber and boolean options)embedblocks (requiresurl)voiceoverblocks (requiresfile)mathblocks (validates non-empty content)preblocks (warns about empty content)
- Frontmatter validation - Validates YAML frontmatter with required
idfield and optionaltitle,peek - Node link extraction - Extracts
node:URLs from markdown links and validates URL format - Section validation - Validates section IDs are present, non-empty, and unique across documents
- Reference validation - Detects broken references to non-existent section IDs
- Inline math validation - Validates
:math[...]syntax for proper bracket closure and non-empty content - Diagnostic formatting - Outputs errors and warnings in text or JSON format with LSP-compatible positioning
What It Doesn't Do
This package intentionally does not:
- Render HTML or other output formats
- Provide a full Markdown parser
- Include heavy dependencies
It's designed to be fast and lightweight for use in editors and CI pipelines.
Installation
pnpm add @weave-md/validateCLI Usage
# Validate a workspace
weave-md-validate ./path/to/content
# Output JSON for CI integration
weave-md-validate ./path/to/content --format jsonNote: CLI tool is planned but not yet implemented
Programmatic Usage
import {
parseFrontmatter,
extractNodeLinks,
validateSections,
validateWeaveBlocks,
validateInlineSyntax,
validateReferences,
formatDiagnostics
} from '@weave-md/validate';
const content = `---
id: intro
title: Introduction
---
See [next section](node:next).
\`\`\`image
file: photo.jpg
alt: A photo
width: wide
\`\`\`
:math[ x^2 + y^2 = z^2 ]
`;
// Parse and validate frontmatter
const { frontmatter, body, diagnostics: fmDiagnostics } = parseFrontmatter(content);
// Extract and validate node links
const { links, errors: linkErrors } = extractNodeLinks(body);
// Validate Weave blocks
const blockDiagnostics = validateWeaveBlocks(content);
// Validate inline syntax
const inlineDiagnostics = validateInlineSyntax(content);
// Format all diagnostics
const allDiagnostics = [...fmDiagnostics, ...linkErrors, ...blockDiagnostics, ...inlineDiagnostics];
console.log(formatDiagnostics(allDiagnostics));Related Packages
@weave-md/core- Core types and helpers (peer dependency)@weave-md/parse- Full AST generation with parse-time validation@weave-md/basic- CLI and rendering (uses both parse and validate)
Dependencies
@weave-md/core- Core types and helpersyaml- YAML parsing
License
MIT
