Generate Markdown files

Generate Markdown files

Ever wondered how to DRY (Don’t Repeat Yourself) in a file? Or generate contents in any Markdown file? As it turns out, it’s quite simple.

Markdown & JavaScript file

Create a Markdown file as usual. Then in the places where you want to have generated contents, put:

Plain Text

Where foo is the name of your function. You can have many functions, and you put them all in a complementary JavaScript file:


Because it’s a regular JavaScript file, you can include all files from your projects and generate contents with e.g. settings, default values, API functions, CLI parameters, etc.

It is also possible to include the JavaScript code directly in the mmd blocks and get rid of the supporting JavaScript file.


First, install the mmarkdown npm package as a devDependency.

As part of your build process, run mmarkdown. In the simplest case, it can be a separate npm script. Also include the configuration in package.json:


Leave a Reply

Notify of