Services API
Scanner service — top-level validation orchestrator.
:class:Scanner is the Facade for the entire validation pipeline.
Callers (CLI, tests, external code) only need to interact with this class;
they do not need to know about parsers, loaders, or evaluators.
Design pattern: Facade — :class:Scanner presents a single, simple
interface over the multi-step parse → load → evaluate pipeline.
Usage::
from markdown_validator.services.scanner import Scanner
scanner = Scanner()
report = scanner.validate(
markdown_file="docs/article.md",
rules_file="rules/tutorial.json",
)
print(report.passed, report.score, report.total_rules)
Scanner
Orchestrates the end-to-end markdown validation pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repository
|
RuleSetRepository | None
|
Optional custom :class: |
None
|
Source code in markdown_validator/services/scanner.py
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 | |
validate(markdown_file: str | Path, rules_file: str | Path) -> ScanReport
Validate a single Markdown file against a rule-set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markdown_file
|
str | Path
|
Path to the |
required |
rules_file
|
str | Path
|
Path to the rule-set JSON file. |
required |
Returns:
| Type | Description |
|---|---|
ScanReport
|
A frozen :class: |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If either file does not exist. |
ValueError
|
If the rule-set JSON is invalid. |
Source code in markdown_validator/services/scanner.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
validate_directory(directory: str | Path, rules_file: str | Path) -> list[ScanReport]
Validate all .md files under directory.
The rule set is loaded once and reused for every file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str | Path
|
Root directory to scan recursively. |
required |
rules_file
|
str | Path
|
Path to the rule-set JSON file. |
required |
Returns:
| Type | Description |
|---|---|
list[ScanReport]
|
List of :class: |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the rule-set file does not exist. |
NotADirectoryError
|
If directory is not a directory. |
Source code in markdown_validator/services/scanner.py
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 | |
validate_with_ruleset(markdown_file: str | Path, rule_set: RuleSetModel) -> ScanReport
Validate a Markdown file against an already-loaded rule set.
This method is useful when the rule set has already been loaded (e.g., to validate multiple files against the same rules without re-reading the JSON on each call).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markdown_file
|
str | Path
|
Path to the |
required |
rule_set
|
RuleSetModel
|
Pre-loaded, validated rule set. |
required |
Returns:
| Type | Description |
|---|---|
ScanReport
|
A frozen :class: |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If markdown_file does not exist. |
Source code in markdown_validator/services/scanner.py
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 | |
Workflow execution engine.
A workflow is an ordered sequence of steps that combines the results of individual validation rules into a higher-level pass/fail decision. Steps are encoded in a mini-language::
S-1,1-D,T-2,F-3,M-E
Each token is <source>-<target> where source/target are either a rule ID
(integer) or a control symbol (S, D, T, F, M, E,
R). Twelve step patterns are supported; see :meth:WorkflowEngine.run.
Design pattern: Chain of Responsibility — each step pattern is dispatched to its own handler method, making the state machine readable and individually testable.
WorkflowEngine
Executes workflow step sequences against a set of rule results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule_results
|
dict[int, bool]
|
Mapping from rule ID to the boolean pass/fail result for that rule, as produced by the scanner. |
required |
Source code in markdown_validator/services/workflow.py
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 | |
run(workflow: WorkflowModel) -> WorkflowResult
Execute a single workflow and return its result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow
|
WorkflowModel
|
The workflow definition (already normalised). |
required |
Returns:
| Type | Description |
|---|---|
WorkflowResult
|
A :class: |
Source code in markdown_validator/services/workflow.py
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 | |
run_all_workflows(rule_set: RuleSetModel, scan_report: ScanReport) -> list[WorkflowResult]
Run every workflow defined in rule_set against scan_report results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule_set
|
RuleSetModel
|
The rule set containing workflow definitions. |
required |
scan_report
|
ScanReport
|
The scan report produced by the scanner for the same document and rule set. |
required |
Returns:
| Type | Description |
|---|---|
list[WorkflowResult]
|
List of :class: |
Source code in markdown_validator/services/workflow.py
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 | |