Run a pre-flight check on Markdown files before committing blog postings
Run this script from inside your git
repository with your blog Markdown files.
The script will attempt to find the file check-markdown-files.conf
in the root of your repository, which includes your configuration.
In order to use this script as git commit
hook, you have to execute it from .git/hooks/pre-commit
, or make this script a symlink (Linux/Unix only).
The following example assumes that you are currently in the root directory of your blog repository, and this repository is checked out next to your blog repository.
cd .git/hooks/ && ln -s ../check-markdown-files/check-markdown-files.py pre-commit && cd -
In check-markdown-files.conf
, the following checks and config options are available. All checks are disabled by default, and can be enabled in the configuration file.
If a check is enabled, it applies to all Markdown files (global configuration). Most checks can be disabled on a local level, using flags in the suppresswarnings
header in Frontmatter.
All available checks are listes in the CHECKS document.
Add the following parts:
read_config
in check-markdown-files.py
handle_markdown_file
in check-markdown-files.py
CHECKS.md
tests/
tests.yml
All tests are found in the tests/
directory, or a subdirectory. Tests are defined in the tests.yml
file, and run by the run-tests.py
script.
Add the new test in tests.yml
, as example:
new_test:
rc_expected: 0
cmdoptions: ""
test_subdirectory: ""
stdout_expected: False
stderr_expected: False
stdout_must_include: []
stderr_must_include: []
stdout_must_not_include: []
stderr_must_not_include: []
The following options are available:
rc_expected
: This is the expected return code of check-markdown-files.py
when running this testcmdoptions
: Which additional options to use when running the testtest_subdirectory
: In which subdirectory under tests
is the teststdout_expected
: Does this test expect output on stdout - if this is set to false, and output is produced, this is an errorstderr_expected
: Does this test expect output on stderr - if this is set to false, and output is produced, this is an errorstdout_lines_expected
: how many lines are expected on stdout - if the number of lines differ, this is an errorstderr_lines_expected
: how many lines are expected on stderr - if the number of lines differ, this is an errorstdout_must_include
: list of strings which must appear in the stdout outputstderr_must_include
: list of strings which must appear in the stderr outputstdout_must_not_include
: list of strings which must not appear in the stdout outputstderr_must_not_include
: list of strings which must not appear in the stderr outputThe following files are used:
tests/new_test.conf
: This is the configfile for the test, enable all tests which should runtests/new_test.input
: If this file exist, it will overwrite tests/new_test.md
before the test is run, also tests/new_test.md
will be deleted afterwardstests/new_test.md
: The Markdown file for this testtests/new_test.expected
: If this file exists, the content is matched against tests/new_test.md
after the test - if the files differ, this is an error