mdt
update markdown content anywhere using comments as template tags
Why?
Often, while developing a project, you will want to automatically update sections of markdown content in your files. For example:
- The
versionhas been updated and should be reflected in multiple files. - The API has changed and you want to automatically generate documentation that is placed within the
readme.mdfile.
Solution
This project allows you to wrap the content you want to keep updated in a markdown comment block <!-- ={exampleBlock} --><!-- {/exampleBlock}-->. A build command is then run which injects values into the comment tag while preserving the tags. This means that blocks can be updated multiple times with new data.
Blocks can also be checked during continuous integration to ensure that they are up-to-date.
Deeper Explanation
Here is a deeper explanation of the mdt flow.
Step 1: Define templates
Define replacement blocks within the markdown content. A replacement block is defined with the following syntax:
Opening tag
Closing Tag
This markdown content can be anywhere that takes markdown content. For example you might want to keep you readme.md up to date with the latest API documentation. You can do this by adding the following to your readme.md file:
This is automatically replaced with the API documentation.
You may also want to reuse code examples in multiple places without having to redefine the multiple times. Below is an example of using the templates in rust files. The same flow can be used for TypeScript, Dart and other languages that support markdown in their documentation comments.
//! This is the API documentation for my_precious
//!
//! # Examples
//!
//! The block below will automatically be replaced when running the `mdt`
//! command.
//!
//! <!-- ={codeExample} -->
//! ```rust
//! use my_precious::be_precious;
//!
//! be_precious();
//! ```
//! <!-- {/codeExample} -->
Step 2: Define definition files
The tags in the previous step are pulling in their content from somewhere. In mdt this is from the definition files. A definition file is a markdown file with the following naming convention *.t.md.
These file are comprised of template blocks of content where the blocks used in the previous section are defined.
Defining a template block
This content will be injected into any markdown content which has the following tag
```markdown
...
```
Defining a template block with template values
In the following example the {{example.version}} is a template value. This value will be replaced with the value defined in the configuration when running the mdt command.
```ts
import { bePrecious } from "https://deno.land/x/my_precious@{{example.version}}/mod.ts";
bePrecious();
```
Step 3: Define the template values
The template values can be defined in the following ways.
mdt.jsonmdt.yamlmdt.kdlmdt.tomlmdt.ts- recommended (see below)
Installation
[]
= "0.0.0"