command line tool and requirable module
npm install md-minify -g
- Wanted to convert markdown to a string
- Wanted to be able to inject markdown into json config files as a property.
There are two ways to use mdm. You can install it globally and use it from the command line, or you can require it in your project.
#####From the command line:
You can use the mdm
command on a markdown file
and it will output the results to the console:
mdm example-readme.md
Pipe the results to a file:
mdm example-readme.md > example-readme.txt
If you include a json file as a second argument it will add a property of "readme":
mdm example-readme.md example-json.json
#####Example usage in your project:
var express = require('express'),
mdm = require('md-minify');
mdm.read(__dirname + "/example-readme.md")
.then(function(content){
var readme = mdm.parse(content);
// do something with content
// add to config file
// or save to db
}).catch(function(error){
console.log(error.message);
// do something with error
});
read
is a wrapper around [q-io/fs read], it takes a markdown file and reads its entire contents into memory. It returns a promise for the whole file contents.
return mdm.read(__dirname + '/example-markdown.md')
.then(function (content) {
// ...
})
parse
replaces line returns with \r\n
and returns string.
var parsedContent = mdm.parse(content);
parseEsc
escapes line returns (\\r\\n
) and returns string.
var parsedEscContent = mdm.parseEsc(content);
saveConfig
takes a path to a config file and the parsed content, and adds a readme property to the config file.
It returns a promise for the whole file contents.
return mdm.saveConfig(__dirname + '/example-json.json', configData)
.then(function (content) {
// ...
})
compare
an object or JSON.parsable string against another object. It returns true or false.
mdm.compare([String|Object], Object)
// returns true or false