Markdowny

Markdowny is a NPM package I wrote many years ago that gives me a lot of basic queries while working with Markdown files. I haven't updated it much, but it covers a lot of my use cases.

Installation

Since I use MfGames Writing in my writing, I already have the required package.json file there so installing is pretty simple.

$ npm install -D markdown

Word Counts

The drawback of most word counts is that they include the top matter which is metadata about the chapter. I don't want to include those, so I use markdowny-wc to count words while excluding the top matter.

$ markdowny-wc src/chapters/*.md
chapter-001.md:   1021
chapter-002.md:   2475
...
chapter-061.md:   1321

I can also get a grand total:

$ markdowny-wc src/chapters/*.md --total
chapter-001.md:   1021
chapter-002.md:   2475
...
chapter-061.md:   1321
Totals        : 119619

Summaries

One of the other conventions is that I put the chapter summary into the YAML as I write. That prevents me from doing a chapter synopsis at the end but it also allows me to easily dump the results.

$ markdowny list chapters/chapter-*.md
1. Always Moving: While Linsan Sterlig waits for her mother to come home, she bounces around on the furniture and talks to her father. She announces that she has named a violin her father is making Palisis and learns that the violin is for her father's first wife who got married to her mother's best friend.

...

60. Proof: Linsan has the opportunity to prove that she has played Palisis before, but there are some disagreements.

61. Decisions: Linsan, Brook, and Miska have to decide what comes next.

The default is to write something that plays well with Markdown or pasting directly into an email since my writing group requires a “story up to this point” with every submission.

Content

If I just want to strip off the top matter (which I didn't find an easy option to do so), I can use the markdowny content command.

$ markdowny content src/chapters/chapter-001.md | head -n 3
> For eight generations, the Sterlig Family crafted some of the most treasured string instruments throughout Gepaul. --- _History of Traditional Music_

Linsan bounced on her family's new couch. With a flip of her green skirt, she did a somersault along the cushions before flopping against the opposite arm. The couch creaked from the impact but she didn't care. With a grin, she pushed herself over the edge until her head dangled over the blue-and-white patterned rug below.

Table

All those are simple usages, but one of the most useful one is creating a table of data from the top matter. This is the markdowny table command but it does have a lot more options, including a few that are undocumented (bad Dylan):

$ markdowny table src/chapters/*.md
markdowny table chapters/*.md
| _basename      | title                 |
| :------------- | :-------------------- |
| chapter-001.md | Always Moving         |
| chapter-002.md | Early Lessons         |
| chapter-003.md | Home Early            |

If you don't know, the output is suitable as a Markdown table and can be used here.

_basename title
chapter-001.md Always Moving
chapter-002.md Early Lessons
chapter-003.md Home Early

The --fields can take a space-separated, dotted notation of any field in the YAML header. If the result is a list, it will make a comma-separated list. For example, to list all the secondary characters in the first three chapters of Sand and Blood, I use the following command:

$ markdowny table src/chapters/*.md --fields title characters.secondary
title characters.secondary
Rutejìmo Hyonèku
Confession Somiryòki, Tejíko, Gemènyo
Morning Desòchu, Gemènyo, Hyonèku, Mapábyo, Opōgyo, Panédo

If I want to get the time and duration of each chapter.

$ markdowny table src/chapters/*.md --fields title when.start when.duration
title when.start when.duration
Rutejìmo 1471/3/28 MTR 4::22 0::30
Confession 1471/3/28 MTR 4::75 0::25
Morning 1471/3/28 MTR 11::71

There are a couple hidden fields also.

$ markdowny table src/chapters/*.md --fields title, _basename, _filename, _words
title _basename _filename _words
Rutejìmo chapter-01.md chapters/chapter-01.md 1520
Confession chapter-02.md chapters/chapter-02.md 2144
Morning chapter-03.md chapters/chapter-03.md 2905

Future Plans

While I haven't done much work recently with markdowny, I'm hoping to write a C# or Rust version that does more. But this is still pretty powerful for giving an overview of the entire chapter using arbitrary YAML top matter you can decide on.