Core linting engine for mdbook-lint
This crate provides the foundational infrastructure for markdown linting with mdBook support. It defines the core abstractions and engine that powers mdbook-lint's rule-based linting system.
Overview
The mdbook-lint-core crate provides:
- Plugin-based architecture for extensible rule sets
- AST and text-based linting with efficient document processing
- Violation reporting with detailed position tracking and severity levels
- Automatic fix infrastructure for correctable violations
- Configuration system for customizing rule behavior
- Document abstraction with markdown parsing via comrak
Architecture
The core follows a plugin-based architecture where rules are provided by external crates:
┌─────────────────┐
│ Application │
└────────┬────────┘
│
┌────────▼────────┐
│ PluginRegistry │ ◄─── Registers rule providers
└────────┬────────┘
│
┌────────▼────────┐
│ LintEngine │ ◄─── Orchestrates linting
└────────┬────────┘
│
┌────────▼────────┐
│ Rules │ ◄─── Individual rule implementations
└─────────────────┘
Basic Usage
Creating a Lint Engine
use ;
use PathBuf;
// Create an empty engine (no rules registered)
let registry = new;
let engine = registry.create_engine?;
// Lint a document
let document = new?;
let violations = engine.lint_document?;
// No violations since no rules are registered
assert_eq!;
# Ok::
With Rule Providers
use ;
// Assumes mdbook-lint-rulesets is available
// use mdbook_lint_rulesets::{StandardRuleProvider, MdBookRuleProvider};
use PathBuf;
let mut registry = new;
// Register rule providers
// registry.register_provider(Box::new(StandardRuleProvider))?;
// registry.register_provider(Box::new(MdBookRuleProvider))?;
// Create engine with registered rules
let engine = registry.create_engine?;
// Lint a document
let content = "# Title\n\n\n\nToo many blank lines";
let document = new?;
let violations = engine.lint_document?;
// Process violations
for violation in violations
# Ok::
Key Types
Document
Represents a markdown file with its content and metadata:
use Document;
use PathBuf;
use Arena;
let doc = new?;
// Parse AST with comrak Arena
let arena = new;
let ast = doc.parse_ast;
// Get document lines
let lines = &doc.lines;
# Ok::
Violation
Represents a linting violation with location and optional fix:
use ;
let violation = Violation ;
Rule Traits
Rules can be implemented using different traits based on their needs:
Rule- Base trait for all rulesAstRule- For rules that analyze the markdown ASTTextRule- For rules that analyze raw textRuleWithConfig- For rules that support configuration
Configuration
Rules can be configured through TOML configuration files:
# .mdbook-lint.toml
[]
= 120
= false
[]
= 2
# Disable specific rules
[]
= false
= false
Features
This crate has no optional features. All functionality is included by default.