This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
Adding Content Parsers
Lakshan Perera edited this page Sep 16, 2012
·
4 revisions
By default, Punch parses content written in Markdown. You can extend this behaviour to support other formats, by writing custom parsers.
Here's how a parser should be implemented:
module.exports = {
supportedExtensions: [".markdown", ".md"],
parse: function(input, callback) {
var self = this;
var output, err;
// do the parsing
return callback(err, output);
},
setup: function(config) {
// Use configuration options.
// By convention, parser releated configurations
// must be set in config.parser (eg. config.parser.markdown)
}
};
Parser should define a parse
function, that takes in an input and a callback. After parsing, the callback should be invoked with the output (or an error).
To use a custom parser in a project, you have to define it as a plugin in project's configuration (config.json
).
"plugins": {
"parsers": {
".format": "custom_parser"
}
}
The key should be the extension of the files your parser is capable of parsing. Parser should be specified as a valid Node.js module path.