Skip to main content

Markdown Dead Link Checker

GitHub Action Ubuntu Windows MacOS

This handy tool helps you maintain the integrity of your Markdown files by identifying broken links. It scans your files and detects:

Here's what it does:

  • Missing webpages: Links that no longer exist on the internet.
  • Incorrect file links: Links that point to the wrong file in your project.
  • Non-existent fragments (anchors): Links to specific sections that don't exist, e.g. README.md#no-fragment.

Example of output for fail.md

File: tests/test_md_files/fail.md:3 • Link: https://github.com/AlexanderDokuchaev/FAILED • Error: 404: Not Found
File: tests/test_md_files/fail.md:4 • Link: https://not_exist_github.githubcom/ • Error: 500: Internal Server Error
File: tests/test_md_files/fail.md:8 • Link: /test/fail.md1 • Error: Path not found
File: tests/test_md_files/fail.md:9 • Link: fail.md1 • Error: Path not found
File: tests/test_md_files/fail.md:13 • Link: /tests/test_md_files/fail.md#fail • Error: Fragment not found
File: tests/test_md_files/fail.md:15 • Link: not_exist_dir • Error: Path not found
❌ Found 6 dead links 🙀

How to Use It

Option 1: GitHub Actions

Add Github Action config to .github/workflow/

jobs:
  md-dead-link-check:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - uses: AlexanderDokuchaev/md-dead-link-check@v1.2.0

Option 2: Pre-Commit

Adding to your .pre-commit-config.yaml to integrate in pre-commit tool

  - repo: https://github.com/AlexanderDokuchaev/md-dead-link-check
    rev: "v1.2.0"
    hooks:
      - id: md-dead-link-check
# .github/workflows/nightly.yaml
name: nightly
on:
  workflow_dispatch:
  schedule:
    - cron: '0 0 * * *'
jobs:
  md-dead-link-check:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - uses: AlexanderDokuchaev/md-dead-link-check@v1.2.0
# .github/workflows/pull_request.yaml
name: pull_request
on:
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
jobs:
  md-dead-link-check:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - uses: AlexanderDokuchaev/md-dead-link-check@v1.2.0

Option 3: Install from pip

For direct use, install with pip and run:

pip install md-dead-link-check
md-dead-link-check

Performance

This tool utilizes asynchronous API calls and avoids downloading full web pages, enabling it to process thousands links in several seconds.

Proxy

This tool leverages your system's existing HTTP and HTTPS proxy configuration. It achieves this by trusting the environment variables that your operating system utilizes to define proxy settings. This functionality is enabled by the aiohttp.ClientSession(trust_env=True) option. For further technical details, you can refer to the aiohttp documentation.

Configuration

This tool seamlessly integrates with your project's pyproject.toml file for configuration. To leverage a different file, invoke the --config option during execution.

  • timeout: Specifies the maximum time (in seconds) to wait for web link responses. Default: 5 seconds.
  • catch_response_codes: List of HTTP response codes to consider as failures. If empty, all codes greater than 400 will be marked as failures. Default: [404, 410, 500].
  • exclude_links: List of links to exclude from checks. Default: [].
  • exclude_files: List of files to exclude from checks. Default: [].
  • force_get_requests_for_links: List of links for which the tool will use GET requests during checks. Default: [].
  • check_web_links: Toggle web link checks on or off. Default: true.
  • validate_ssl: Toggles whether to validate SSL certificates when checking web links. Default: true.
  • throttle_groups: Number of domain groups to divide requests across for throttling. Default: 100 seconds.
  • throttle_delay: Time to wait between requests, scaled by domain load and group size. Default: 20 seconds.
  • throttle_max_delay: Maximum allowable delay (in seconds) for throttling a single domain. Default: 100 seconds.
[tool.md_dead_link_check]
timeout = 5
exclude_links = ["https://github.com/", "https://github.com/*"]
exclude_files = ["tests/test_md_files/fail.md", "tests/*"]
check_web_links = true
catch_response_codes = [404, 410, 500]
force_get_requests_for_links = []
validate_ssl = true
throttle_groups = 100
throttle_delay = 20
throttle_max_delay = 100

Rate Limiting and Request Throttling

Websites often have limits on how many requests you can make within a certain period. If these limits are exceeded, the server will return a 429 Too Many Requests status code.

Failure Handling

By default, the 429 status code is treated as a warning. You can modify this behavior and configure how the tool handles different status codes.

catch_response_codes = [404, 410, 429, 500]

Throttling Mechanism

To prevent your requests from overwhelming a website and potentially getting you blocked, this tool implements a throttling mechanism. This mechanism limits the number of requests that can be made in a given period.

You can control the following parameters to fine-tune request throttling:

throttle_groups = 40  # default: 100
throttle_delay = 30  # default: 20
throttle_max_delay = 240  # default: 100

By filtering out non-critical links and files, you can stay within rate limits while throttling requests.

Exclude specific URLs that match patterns:

exclude_links = ["https://github.com/AlexanderDokuchaev/md-dead-link-check/pull/*"]

Exclude Specific Files

Prevent specific files (e.g., changelogs) from being checked:

exclude_files = ["CHANGELOG.md"]

Exclude Parts of Files Using Comments

Ignore sections of files using a special comment <!-- md-dead-link-check: off -->.

...

<!-- md-dead-link-check: off -->

All links will be ignored in this part of the file.

<!-- md-dead-link-check: on -->

...

Metadata

Release files for md-dead-link-check 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for md-dead-link-check 1.3.0
File Size Uploaded Provenance Actions
md_dead_link_check-1.3.0.tar.gz 19.1 kB Without provenance Details for md_dead_link_check-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for md-dead-link-check 1.3.0
File Interpreter ABI Platform Actions
md_dead_link_check-1.3.0-py3-none-any.whl Python 3 none any Details for md_dead_link_check-1.3.0-py3-none-any.whl

Total release size: 33.3 kB

Security for md-dead-link-check 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page