anetczuk / mdlinkscheck

Verify if links and images in Markdown are valid.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 extenal URLs are reachable
  • ignore Markdown syntax in code blocks (C++ lambdas syntax is simillar to Markdown links)

Running

There is description of command line arguments. To simple run execute (dedicated script):

checkmdlinks.py --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.

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).

Development

There are couple of helpfull scripts to run:

  • src/install-deps.sh - installation of dependencies
  • src/install-package.sh - installation of package (normal mode)
  • src/install-devel.sh - installation of package in editable mode
  • src/testmdlinkscheck/runtests.py - runner for unit tests
  • tools/checkall.sh - execute static code checks against source code
  • tools/installvenv.sh - prepare venv with package
  • process-all.sh - run all tests (in venv), generators and code checks

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.

About

Verify if links and images in Markdown are valid.

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 75.6%Language:Shell 24.4%