1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//! 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:
//!
//! ```text
//! ┌─────────────────┐
//! │ Application │
//! └────────┬────────┘
//! │
//! ┌────────▼────────┐
//! │ PluginRegistry │ ◄─── Registers rule providers
//! └────────┬────────┘
//! │
//! ┌────────▼────────┐
//! │ LintEngine │ ◄─── Orchestrates linting
//! └────────┬────────┘
//! │
//! ┌────────▼────────┐
//! │ Rules │ ◄─── Individual rule implementations
//! └─────────────────┘
//! ```
//!
//! # Basic Usage
//!
//! ## Creating a Lint Engine
//!
//! ```rust
//! use mdbook_lint_core::{PluginRegistry, Document};
//! use std::path::PathBuf;
//!
//! // Create an empty engine (no rules registered)
//! let registry = PluginRegistry::new();
//! let engine = registry.create_engine()?;
//!
//! // Lint a document
//! let document = Document::new("# Hello\n\nWorld".to_string(), PathBuf::from("test.md"))?;
//! let violations = engine.lint_document(&document)?;
//!
//! // No violations since no rules are registered
//! assert_eq!(violations.len(), 0);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## With Rule Providers
//!
//! ```rust,no_run
//! use mdbook_lint_core::{PluginRegistry, Document};
//! // Assumes mdbook-lint-rulesets is available
//! // use mdbook_lint_rulesets::{StandardRuleProvider, MdBookRuleProvider};
//! use std::path::PathBuf;
//!
//! let mut registry = PluginRegistry::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 = Document::new(content.to_string(), PathBuf::from("test.md"))?;
//! let violations = engine.lint_document(&document)?;
//!
//! // Process violations
//! for violation in violations {
//! println!("{}:{} - {}", violation.rule_id, violation.line, violation.message);
//! }
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! # Key Types
//!
//! ## Document
//!
//! Represents a markdown file with its content and metadata:
//!
//! ```rust
//! use mdbook_lint_core::Document;
//! use std::path::PathBuf;
//! use comrak::Arena;
//!
//! let doc = Document::new(
//! "# My Document\n\nContent here".to_string(),
//! PathBuf::from("doc.md")
//! )?;
//!
//! // Parse AST with comrak Arena
//! let arena = Arena::new();
//! let ast = doc.parse_ast(&arena);
//!
//! // Get document lines
//! let lines = &doc.lines;
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Violation
//!
//! Represents a linting violation with location and optional fix:
//!
//! ```rust
//! use mdbook_lint_core::violation::{Violation, Severity, Fix, Position};
//!
//! let violation = Violation {
//! rule_id: "MD001".to_string(),
//! rule_name: "heading-increment".to_string(),
//! message: "Heading levels should increment by one".to_string(),
//! line: 5,
//! column: 1,
//! severity: Severity::Warning,
//! fix: Some(Fix {
//! description: "Change heading level".to_string(),
//! replacement: Some("## Correct Level".to_string()),
//! start: Position { line: 5, column: 1 },
//! end: Position { line: 5, column: 20 },
//! }),
//! };
//! ```
//!
//! ## Rule Traits
//!
//! Rules can be implemented using different traits based on their needs:
//!
//! - `Rule` - Base trait for all rules
//! - `AstRule` - For rules that analyze the markdown AST
//! - `TextRule` - For rules that analyze raw text
//! - `RuleWithConfig` - For rules that support configuration
//!
//! # Configuration
//!
//! Rules can be configured through TOML configuration files:
//!
//! ```toml
//! # .mdbook-lint.toml
//! [rules.MD013]
//! line_length = 120
//! code_blocks = false
//!
//! [rules.MD009]
//! br_spaces = 2
//!
//! # Disable specific rules
//! [rules]
//! MD002 = false
//! MD041 = false
//! ```
//!
//! # Features
//!
//! This crate has no optional features. All functionality is included by default.
// Re-export core types for convenience
pub use Config;
pub use Document;
pub use ;
pub use ;
pub use RuleRegistry;
pub use ;
pub use ;
/// Current version of mdbook-lint-core
pub const VERSION: &str = env!;
/// Human-readable name
pub const NAME: &str = "mdbook-lint-core";
/// Description
pub const DESCRIPTION: &str = "Core linting engine for mdbook-lint";
/// Create a lint engine with all available rules (standard + mdBook)
/// Note: Requires mdbook-lint-rulesets dependency for rule providers
/// Create a lint engine with only standard markdown rules
/// Note: Requires mdbook-lint-rulesets dependency for rule providers
/// Create a lint engine with only mdBook-specific rules
/// Note: Requires mdbook-lint-rulesets dependency for rule providers
/// Common imports