markdown-crossref-validator
10
总安装量
10
周安装量
#30504
全站排名
安装命令
npx skills add https://github.com/prulloac/agent-skills --skill markdown-crossref-validator
Agent 安装分布
codex
10
amp
9
gemini-cli
9
github-copilot
9
kimi-cli
9
opencode
9
Skill 文档
Markdown Cross-Reference Validator
When to use this skill
Use this skill when the user asks to validate or check cross-references in markdown files. This includes verifying that internal links (e.g., text) point to existing headings, and that file references (e.g., text) point to existing files.
Algorithm & Workflow
Phase 1: Document Preparation
- Identify target file(s): Determine which markdown file(s) to validate
- Read content: Load the full markdown document(s) into memory
- Establish base path: Determine the root directory for relative file references
Phase 2: Heading Extraction
- Scan for headings: Find all lines matching regex
^#+\s+(.*)$ - Build anchor map: For each heading:
- Extract heading text:
# IntroductionâIntroduction - Convert to anchor ID: lowercase, replace spaces with hyphens, remove special chars
- Store mapping:
introductionâ heading level (1-6)
- Extract heading text:
- Handle special cases: Account for heading IDs, custom anchors using HTML comments
- Normalize anchors: Ensure consistent anchor formatting for comparison
Phase 3: Link Extraction
- Find all link patterns:
- Inline links:
[text](url)using regex\[([^\]]+)\]\(([^)]+)\) - Reference links:
[text][ref]using regex\[([^\]]+)\]\[([^\]]+)\] - Reference definitions:
[ref]: urlusing regex^\s*\[([^\]]+)\]:\s*(.+)$ - HTML links:
<a href="url">text</a>
- Inline links:
- Categorize links:
- Internal anchors:
#heading-name - File references:
path/to/file.md - Combined:
path/to/file.md#section - External:
http://...,https://... - Relative path:
../other.md
- Internal anchors:
Phase 4: Link Validation
For Internal Anchor Links (#anchor)
- Extract anchor identifier
- Normalize anchor (lowercase, hyphenate)
- Check against anchor map from Phase 2
- Record as â Valid or â Broken
For File References (path/to/file.md)
- Resolve relative path from current document location
- Check file existence in project
- If file + anchor (
path/to/file.md#section):- Verify file exists
- Parse target file for headings
- Verify anchor exists in target file
- Record as â Valid or â Broken with reason
For External Links (http://, https://)
- Mark as external (scope: not validated for internal consistency)
- Optionally note for manual review
Phase 5: Issue Categorization
Classify all broken references by type:
- Missing Heading: Anchor exists but no matching heading in file
- Missing File: File reference path doesn’t exist
- Invalid Anchor in Target: File exists but referenced section doesn’t
- Malformed Reference: Link syntax is invalid or unparseable
Phase 6: Report Generation
- Create summary: Total links checked, valid count, broken count, broken percentage
- Group issues: Organize by file and issue type
- Provide context: Show the line number and actual link text
- Suggest fixes: Recommend corrected anchor names or file paths
- Verify output: Ensure report is complete and accurate
Validation & Verification
Validation Checklist
- â All markdown files are readable and parseable
- â All heading anchors are properly extracted and normalized
- â All link patterns (inline, reference, HTML) are detected
- â Internal anchor references are validated
- â File references exist and are properly resolved
- â Cross-file anchors are verified in target files
- â Report categorizes all issues by type
- â All broken references are identified with context
Report Verification Steps
- Random sample 5-10 links and manually verify they match report findings
- Check that issue count matches actual broken references
- Verify all line numbers and file paths are accurate
- Confirm suggestions for fixes are actionable
Concrete Examples
Example 1: Simple Document with Internal Links
Input: docs/guide.md
# Getting Started Guide
## Table of Contents
- [Installation](#installation)
- [Configuration](#configuration)
- [Advanced Setup](#advanced-setup)
## Installation
Follow these steps to install...
## Configuration
See [Installation](#installation) for prerequisites.
## Advanced Setup
For complex scenarios, refer to [Config](#configuration).
## Troubleshooting
Check [Non-existent Section](#missing-section) for help.
Validation Report:
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
MARKDOWN CROSS-REFERENCE VALIDATION REPORT
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
File: docs/guide.md
Scan Date: 2024-02-21
Status: â VALIDATED WITH ISSUES
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
SUMMARY
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Total Links Found: 5
Valid References: 4
Broken References: 1
Validation Rate: 80%
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
VALID REFERENCES â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Line 4: [Installation](#installation)
Type: Internal anchor
Status: Heading "Installation" found at line 11
â Line 5: [Configuration](#configuration)
Type: Internal anchor
Status: Heading "Configuration" found at line 18
â Line 5: [Advanced Setup](#advanced-setup)
Type: Internal anchor
Status: Heading "Advanced Setup" found at line 22
â Line 19: [Installation](#installation)
Type: Internal anchor (cross-reference)
Status: Valid, heading exists
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
BROKEN REFERENCES â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Line 26: [Non-existent Section](#missing-section)
Type: Internal anchor
Issue: MISSING HEADING
Anchor: #missing-section
Status: No heading found matching "missing-section"
Suggestion: Available sections in document:
- #getting-started-guide (h1)
- #table-of-contents (h2)
- #installation (h2)
- #configuration (h2)
- #advanced-setup (h2)
- #troubleshooting (h2)
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
ANCHOR MAPPING
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
getting-started-guide (Level 1) â Line 1
table-of-contents (Level 2) â Line 3
installation (Level 2) â Line 11
configuration (Level 2) â Line 18
advanced-setup (Level 2) â Line 22
troubleshooting (Level 2) â Line 25
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Example 2: Cross-File References
Input: Multiple files in docs/ directory
Files:
docs/index.md– Main documentation indexdocs/guide/installation.md– Installation guidedocs/guide/config.md– Configuration guidedocs/api/endpoints.md– API reference
Content: docs/index.md
# Documentation Index
- [Installation Guide](guide/installation.md)
- [Configuration](guide/config.md#configuration)
- [API Reference](api/endpoints.md)
- [Getting Help](support/help.md)
- [Basic Setup](#quick-start)
## Quick Start
See [Installation](guide/installation.md#system-requirements) for details.
Validation Report:
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
MARKDOWN CROSS-REFERENCE VALIDATION REPORT
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
File: docs/index.md
Scan Date: 2024-02-21
Status: â VALIDATED WITH CRITICAL ISSUES
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
SUMMARY
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Total Links Found: 6
Valid References: 3
Broken References: 3
Validation Rate: 50%
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
VALID REFERENCES â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Line 3: [Installation Guide](guide/installation.md)
Type: File reference
Path: docs/guide/installation.md
Status: File exists (2.5 KB)
â Line 4: [Configuration](guide/config.md#configuration)
Type: File with anchor
Path: docs/guide/config.md
Anchor: #configuration
Status: File exists, heading found in target
â Line 8: [Installation](guide/installation.md#system-requirements)
Type: File with anchor
Path: docs/guide/installation.md
Anchor: #system-requirements
Status: File exists, heading found in target
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
BROKEN REFERENCES â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Line 5: [API Reference](api/endpoints.md)
Type: File reference
Issue: MISSING FILE
Path: docs/api/endpoints.md
Status: File not found in project
Suggestion: Did you mean?
- docs/api/reference.md (exists)
- docs/endpoints.md (exists)
â Line 6: [Getting Help](support/help.md)
Type: File reference
Issue: MISSING FILE
Path: docs/support/help.md
Status: File not found in project
Suggestion: No similar files found. Check path spelling.
â Line 7: [Basic Setup](#quick-start)
Type: Internal anchor
Issue: MISSING HEADING
Anchor: #quick-start
Status: Anchor not found (likely typo: #quickstart exists)
Suggestion: Did you mean #quickstart?
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
CROSS-FILE ANALYSIS
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Scanned 4 files in project:
- docs/index.md (6 links)
- docs/guide/installation.md (12 links, all valid)
- docs/guide/config.md (8 links, 1 broken)
- docs/api/reference.md (5 links, all valid)
Cross-file reference summary:
- Files referenced: 4
- Valid file references: 3
- Invalid file references: 2
- Unresolvable anchors in targets: 0
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Example 3: Reference-Style Links
Input: docs/readme.md
# Project Documentation
See the [Getting Started][gs] guide for setup instructions.
For API details, check [API Reference][api] or [CLI Reference][cli].
Invalid reference: [Missing Reference][unknown]
[gs]: guide/getting-started.md#prerequisites
[api]: https://api.example.com
[cli]: guide/cli.md#commands
Validation Report:
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
MARKDOWN CROSS-REFERENCE VALIDATION REPORT
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
File: docs/readme.md
Scan Date: 2024-02-21
Type: Reference-style links
Status: â VALIDATED WITH ISSUES
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
SUMMARY
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Total Links Found: 4
Valid References: 3
Broken References: 1
External Links: 1
Validation Rate: 75%
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
REFERENCE DEFINITIONS FOUND
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
[gs] â guide/getting-started.md#prerequisites (Line 9)
[api] â https://api.example.com (Line 10, External)
[cli] â guide/cli.md#commands (Line 11)
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
VALIDATION RESULTS
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â [Getting Started][gs] (Line 3)
Reference defined: Yes
Target: guide/getting-started.md#prerequisites
File status: Exists
Anchor status: Valid
Result: VALID
â [API Reference][api] (Line 5)
Reference defined: Yes
Target: https://api.example.com
Type: External URL
Result: EXTERNAL (not validated)
â [CLI Reference][cli] (Line 5)
Reference defined: Yes
Target: guide/cli.md#commands
File status: Exists
Anchor status: Valid
Result: VALID
â [Missing Reference][unknown] (Line 7)
Reference defined: No
Status: UNDEFINED REFERENCE
Issue: Reference label "[unknown]" not found in definitions
Suggestion: Available references in document:
- [gs]
- [api]
- [cli]
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Tools to use
- Use file reading tools to access markdown files.
- Use grep or parsing to extract links and headings.
- For file existence, use directory listing tools.
Quick Reference: Link Patterns
| Pattern | Example | Type |
|---|---|---|
| Inline link | [text](#anchor) |
Internal anchor |
| Inline file | [text](file.md) |
File reference |
| Combined | [text](file.md#section) |
File with anchor |
| Reference-style | [text][ref] + [ref]: url |
Reference link |
| HTML link | <a href="#id">text</a> |
HTML anchor |
| External | [text](https://example.com) |
External URL |