Skip to main content

verify links in Markdown files

Project description

mdlinkscheck

Simple things can be difficult. Links can be complicated. With this package headache no more.

Package verifies links in Markdown files. Typical use case is to verify Markdown files stored locally (e.g. as part of project's documentation in repository).

Features

  • find Markdown files in subdirectories
  • check standard links
  • check linked images
  • handle relative and absolute links, local and external resources
  • handle links to elements
  • check if external URLs are reachable
  • ignore Markdown syntax in code blocks (C++ lambdas syntax is similar to Markdown links)

How it works?

Library simply converts Markdown to HTML and then extracts links using BeautifulSoup. After that links are verified - this is quite tricky, because links can be absolute, relative, can point to HTML element, can point to local file or external resource. Moreover links can contain e-mail address (mailto:) or JavaScript. Even worse, element links can point to implicit elements (GitHub does it in it's own way, bitbucket does it in different way).

Running

Application accepts following arguments:

usage: checkmdlinks [-h] [-la] [--silence] [-d DIR] [-f N [N ...]]
                   [--excludes N [N ...]] [--implicit-heading-id-github]
                   [--implicit-heading-id-bitbucket] [--check-url-reachable]

check links in Markdown

options:
  -h, --help            show this help message and exit
  -la, --logall         Log all messages
  --silence             Do not output log messages
  -d DIR, --dir DIR     Path to directory to search .md files for for
                        verification
  -f N [N ...], --files N [N ...]
                        Space separated list of paths to files to check
  --excludes N [N ...]  Space separated list of regex strings applied on found
                        files to be excluded from processing
  --implicit-heading-id-github
                        Allow links to sections with implicit id as in GitHub
                        (lowercased ids with dashes)
  --implicit-heading-id-bitbucket
                        Allow links to sections with implicit id as in
                        BitBucket (lowercased ids with dashes and 'markdown-
                        header-' prefix)
  --check-url-reachable
                        Check if external URLs are reachable

To simple run execute:

checkmdlinks --dir <path-to-dir-with-MD-files>

or run as module:

python3 -m mdlinkscheck --dir <path-to-dir-with-MD-files>

Application then will go recursively and look for .md files and validate them. By passing -f with list of files there is possibility to run the check against given files only. Other options include passing particular files and setting compatibility mode with GitHub or BitBucket version of Markdown (anchors deduction).

Installation

Installation of package can be done by:

  • to install using PyPI: pip3 install --user mdlinkscheck
  • to install package from GitHub downloaded ZIP file execute: pip3 install --user -I file:mdlinkscheck-master.zip#subdirectory=src
  • to install package directly from GitHub execute: pip3 install --user -I git+https://github.com/anetczuk/mdlinkscheck.git#subdirectory=src
  • installation from local repository root directory: pip3 install --user .

To uninstall run: pip3 uninstall mdlinkscheck

To install project under virtual environment use tools/installvenv.sh.

Development installation is covered in Development section.

Development

Project contains several tools and features that facilitate development and maintenance of the project.

In case of pull requests please run process-all.sh --release before the request to check installation, run tests and perform source code static analysis.

Installation

Installation for development with configuration of virtual environment:

  • tools/installvenv.sh --dev to install dependencies, the package in editable mode and install development tooling.

Installation for development without venv:

  • src/install-app.sh --dev to install dependencies, the package in editable mode and install development tooling.

Virtual environment can be also configured manually by:

  • python3 -m venv .venv
  • source .venv/bin/activate
  • python -m pip install --upgrade pip
  • src/install-app.sh --dev to install dependencies, the package in editable mode and install development tooling or python -m pip install -e '.[dev]' to install project by hand.

There is also possibility to work on the project without installation. In this case project will run from local repository directory. This configuration requires installation of dependencies: ./src/install-deps.sh --dev.

Running tests

To run tests execute src/testmdlinkscheck/runtests.py. Code coverage can be achieved using coverage.sh and profiling can be calculated with script profiler.sh.

Tools scripts

In tools directory there can be found following helper scripts:

  • codecheck.sh -- static code check using several tools with defined set of rules
  • doccheck.sh -- run pydocstyle with defined configuration
  • mdcheck.sh -- check links in Markdown files
  • typecheck.sh -- run mypy with defined configuration
  • checkall.sh -- execute check scripts all at once
  • profiler.sh -- profile Python scripts
  • coverage.sh -- measure code coverate
  • `notrailingwhitespaces.sh* -- as name states removes trailing whitespaces from .py files
  • rmpyc.sh -- remove all *.pyc files

Those scripts can be run also from within virtual environment.

Similar projects

References

License

BSD 3-Clause License

Copyright (c) 2023, Arkadiusz Netczuk dev.arnet@gmail.com

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdlinkscheck-1.0.4.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdlinkscheck-1.0.4-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file mdlinkscheck-1.0.4.tar.gz.

File metadata

  • Download URL: mdlinkscheck-1.0.4.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mdlinkscheck-1.0.4.tar.gz
Algorithm Hash digest
SHA256 2009bc0c275e2e07ce7aef4e2eb8377c2924c9f16256f3a264c2fd4fe12bc2eb
MD5 6ef59a9127741a7f8f3f6a7334eca460
BLAKE2b-256 b1501b3304bce95dcb790e72a644df7912aac204c859e2283d08033fda3ae3d6

See more details on using hashes here.

File details

Details for the file mdlinkscheck-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: mdlinkscheck-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mdlinkscheck-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 41ef05cc08a1323e1db5c49544d5605b0937eb4337bf588d735f0592362d6a83
MD5 8e86602df215b5c335065626f8a5f493
BLAKE2b-256 4fe76604dcd382dd2698aaccac09c17fa2fb3a541da8545ef0da6ca2556ac864

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page