This package is a port in PHP of Markdown Word Count for Python3. Regular expressions comme from there (except for images) and tests too.
This package helps you count words in a markdown document. It excludes punctuation, footnotes, and special Markdown or HTML tag syntax.
You may use it, for example, to get an estimation of the reading time of an article written in markdown.
The package provides a class with static methods, function helpers and an executable file.
Install with Composer:
composer require arcesilas/md-word-count
use Arcesilas\MdWordCount;
$count = MdWordCount::fromString($markdown);
use Arcesilas\MdWordCount;
$count = MdWordCount::fromFile($file);
if (false === $count) {
// File not found or directory
}
$count = md_word_count($markdown);
$count = md_file_word_count($file);
if (false === $count) {
// File not found or directory
}
bin/mdwc path/to/document.md
The executable echoes the word count from given file and exits with code 0.
If the file does not exists, it exits with code 1.
Please see CHANGELOG for more information on what has changed recently.
Run:
$ composer test
$ composer check-style
See CONTRIBUTING
- Improve the executable with features:
- accept arguments (see
man wc
for examples) - read files from list (or from stdin)
- read content from stdin
- accept arguments (see
Without using symfony/console for such a small command.