Write your code in markdown, then use literate to 'require' the module. The JavaScript you have written in code blocks will be scraped out and returned as the module at runtime.
$ npm install literate
Create a markdown file for you documenation and code (your_module.md
):
# This is an example module.
First it logs to the console:
console.log("hello world")
It exports a function as an example.
module.exports.useAsNormal = function(){
return "foo";
}
You can also set a variable like this `var x = 2`,
and write it out with a `console.log(x)`.
In your main file (server.js
), instead of using require directly, use literate
to load the module:
var your_module = require('literate')('./your_module');
your_module.useAsNormal();
The markdown is available to the module at runtime on a __markdown
variable:
# Retrieve documentation at runtime
module.exports.markdown = function(){
return __markdown;
}
At the moment block are not supported, so you have to write your program in sequence.
MIT