mdoc
Modular documents
With mdoc you can create recursive, modular documents. It has four main features:
- Include entire files in other documents.
- Include snippets of files in other documents.
- Use externally defined variables throughout your documents.
- Evaluate Python expressions inside your documents.
That's the 'modular' part. The 'recursive' part means that the included documents can themselves include other documents, ad infinitum.
For example, this readme was generated from the various pieces sitting in the readme directory.
mdoc tags
mdoc accomplishes all of this by parsing your input files for mdoc tags. These tags look like:
{mdoc include file.ext}, to include the filefile.ext{mdoc snippet eq1 from file.ext}, to include the snippet calledeq1from the filefile.ext{mdoc var1}, to insert the variable calledvar1{mdoc eval expression}, to evaluate the Python expressionexpression
You might be wondering how, if this readme is generated using mdoc, I was able to type {mdoc ...} above without it being parsed. This is thanks to the static option, which prevents included files from being parsed and includes them verbatim:
{mdoc include file.ext static}includesfile.extbut does not parse it for mdoc tags{mdoc include snippet eq1 from file.ext static}includes snippeteq1fromfile.extbut does not parse it for mdoc tags
There is no static option for variables or evals, since that wouldn't make any sense.
Snippets are defined as follows:
# Inside file.ext
{mdoc snip snippet_name}
...
snippet contents
...
{mdoc unsnip snippet_name}
You can then reference the snippet name and the file it lives in to include it in another document:
# Inside main file
{mdoc snippet snippet_name from file.ext}
This is very handy for including snippets of code that may change over time, as well as other fluctuating content.
Of course, the words include, snippet, snip, unsnip and eval are reserved and cannot be used as mdoc variables names.
usage
Using mdoc is simple, once you've installed it. Simply navigate into the folder where your main document template lives and run:
mdoc --input INPUT_DOCUMENT --output OUTPUT_DOCUMENT --variables VARIABLES_JSON
This will parse INPUT_DOCUMENT, insert any variables defined in VARIABLES_JSON, and spit out OUTPUT_DOCUMENT.
If you do not wish to generate an output file and simply want to see what the output would look like, you can replace the --output OUTPUT_DOCUMENT with --dryrun.
If you've lost track of all the variables needed throughout your documents, you can use --showvariables rather than --output or --dryrun and it will spit out a JSON-formatted list of all the variables you need. You can pipe this into a file to make things really easy!
mdoc --input INPUT_DOCUMENT --showvariables > VARIABLES_JSON
Release files for mdoc 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mdoc-0.0.9.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mdoc-0.0.9-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 10.2 kB
Release files / mdoc-0.0.9.tar.gz
| Download URL | mdoc-0.0.9.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
994819f231940867c25da7552022d332e2fd2dac7fbd6c92aa714146fe2eb090
|
|
BLAKE2b-256 checksum How to use checksums |
a3913c3c83e179b037c4f74731ebebfcc210c95fdc2e1f8fe19fbcae81830344
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / mdoc-0.0.9-py2-none-any.whl
| Download URL | mdoc-0.0.9-py2-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
e2f179ccc83307a7bccac4b92738ee0a248f0fa23278306671bf021d7d9df1d2
|
|
BLAKE2b-256 checksum How to use checksums |
f2a877b500d1cbad8060880528015d9860c93d536d25d4f26470c7b94beebdd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |