This project provides a custom Pygments lexer for highlighting Unix crontab files, including:
- User crontabs (
crontab -e) - System-wide crontabs (
/etc/crontab,/etc/cron.d/*) @-directives (@reboot,@daily, etc.)- Extended parsing for:
- Minutes, hours, days, months, weekdays
- Ranges, lists, steps, and wildcards
- Month and weekday names (
jan,feb,mon,sun, …)
- Full syntax highlighting support for all crontab formats
- Proper tokenization of time fields (including ranges and names)
- Works in MediaWiki with the
SyntaxHighlightextension - Distributed as a Python package with Pygments plugin entry point
Follow these steps to install and activate the custom lexer.
git clone https://github.com/b3-it/pygments-lexer-crontab
cd pygments-lexer-crontabpython3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pippip install .or for development mode:
pip install -e .pygmentize -L lexers | grep -i crontabYou should see:
* crontab:
Crontab
Test syntax highlighting:
pygmentize -l crontab -f terminal256 -O style=monokai tests/test.cronMediaWiki does not automatically detect new Pygments lexers.
You must point MediaWiki to your pygmentize binary and refresh the lexer list.
$wgPygmentizePath = '/full/path/to/pygmentize';Example:
$wgPygmentizePath = '/home/username/crontab-lexer/.venv/bin/pygmentize';This step is required once after installation:
cd path/to/mediawiki/extension/syntaxhighlight
php maintenance/updateLexerList.phpAfter this, the crontab language becomes available in <syntaxhighlight>.
<syntaxhighlight lang="crontab">
*/5 * * * * /usr/local/bin/backup.sh
</syntaxhighlight>From your environment:
pip uninstall crontab-lexerIf you want to remove the lexer from MediaWiki:
- Remove or comment out
$wgPygmentizePath. - Regenerate the lexer list again:
cd path/to/mediawiki/extension/syntaxhighlight
php maintenance/updateLexerList.phpMIT License.