Crates.io | count-md |
lib.rs | count-md |
version | 0.1.0 |
source | src |
created_at | 2024-08-02 22:36:57.157356 |
updated_at | 2024-08-02 22:36:57.157356 |
description | A simple, configurable command-line tool and Rust library for Unicode-aware, Markdown-aware, HTML-aware word counting in Markdown documents |
homepage | |
repository | https://github.com/chriskrycho/count-md |
max_upload_size | |
id | 1323838 |
size | 44,402 |
A simple, configurable command-line tool and Rust library for Unicode-aware, Markdown-aware, HTML-aware word counting in Markdown documents.
That is: this tool will correctly count words in a Unicode-aware way, without incorrectly including Markdown syntax or HTML tags. It can include or exclude content like blockquotes, footnotes, code blocks, and so on, and ships with reasonable defaults out of the box for each!
You might have a file with content like this:
# Title
This is some text!
> Here is a quote from someone else.
Here is more text.
If you wanted to know the number of non-quoted words, including the title but not including the blockquote, you would simply run count-md <path to the file>
, and it will helpfully report that there are 9 words total. By contrast, wc -w
will report that there are 18 words: it includes the blockquote, of course, but it also includes the #
for the title and the >
for the blockquote, neither of which is desirable!
Support for including or or excluding the following Markdown features:
The core functionality here can be used as a Rust library.2 There are two main entry points:
count
: accepts a &str
and counts it with the default set of options, equivalent to running count-md
with zero options on the command line.
count_with_options
: accepts a &str
and an Options
value (a bitmask), which allows you to configure each option directly. For the equivalent to running count-md
with some option, use Options::DEFAULT
and combine it with other flags:
With bitmasking directly: Options::DEFAULT | Options::IncludeBlockquotes
With the methods supplied by the bitflags
library, insert
and remove
:
let mut options = Options::DEFAULT;
options.insert(Options::IncludeBlockquotes);
options.remove(Options::IncludeHeadings);
See the documentation for more!