Skip to content

Commit

Permalink
Enable markdown for all description fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
rottmann committed Jul 10, 2014
1 parent 68e1ead commit 705ee7b
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 171 deletions.
23 changes: 23 additions & 0 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var fs = require("fs");
var path = require("path");
var util = require("util");
var _ = require("underscore");
var markdown = require("marked");

var app = {};

Expand All @@ -17,6 +18,9 @@ function Parser(_app)
self.parsedFileElements = [];
self.parsedFiles = [];

// Markdown settings
markdown.setOptions(app.options.marked);

// Parser laden
var parsers = Object.keys(app.parsers);
parsers.forEach(function(parser) {
Expand Down Expand Up @@ -116,6 +120,25 @@ Parser.prototype._parseBlockElements = function(indexApiBlocks, detectedElements
var result = null;
try {
result = self.parsers[element.name].parse(element.content, element.source);

// Markdown
// TODO: Evaluate if better add a function in specific worker_{name}.js
if(app.options.marked.gfm &&
self.parsers[element.name].markdownFields &&
self.parsers[element.name].markdownFields.length > 0
)
{
for(var markdownIndex = 0; markdownIndex < self.parsers[element.name].markdownFields.length; markdownIndex += 1)
{
var markdownField = self.parsers[element.name].markdownFields[markdownIndex];
if(result[markdownField])
{
result[markdownField] = markdown(result[markdownField]);
// remove line breaks.
result[markdownField] = result[markdownField].replace(/(\r\n|\n|\r)/g, "");
}
} // for
}
}
catch(e)
{
Expand Down
3 changes: 2 additions & 1 deletion lib/plugins/parser_api_define_permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ function pushTo()
*/
module.exports = {
parse: parse,
pushTo: pushTo
pushTo: pushTo,
markdownFields: [ "description" ]
};
3 changes: 2 additions & 1 deletion lib/plugins/parser_api_description.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ function pushTo()
*/
module.exports = {
parse: parse,
pushTo: pushTo
pushTo: pushTo,
markdownFields: [ "description" ]
};
3 changes: 2 additions & 1 deletion lib/plugins/parser_api_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ function pushTo()
*/
module.exports = {
parse: parse,
pushTo: pushTo
pushTo: pushTo,
markdownFields: [ "description" ]
};
3 changes: 2 additions & 1 deletion lib/plugins/parser_api_group_description.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ function pushTo()
*/
module.exports = {
parse: parse,
pushTo: pushTo
pushTo: pushTo,
markdownFields: [ "groupDescription" ]
};
3 changes: 2 additions & 1 deletion lib/plugins/parser_api_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ function pushTo()
*/
module.exports = {
parse: parse,
pushTo: pushTo
pushTo: pushTo,
markdownFields: [ "description" ]
};
3 changes: 2 additions & 1 deletion lib/plugins/parser_api_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ function pushTo()
*/
module.exports = {
parse: parse,
pushTo: pushTo
pushTo: pushTo,
markdownFields: [ "description" ]
};
3 changes: 2 additions & 1 deletion lib/plugins/parser_api_param.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ function getGroup()
module.exports = {
parse: parse,
pushTo: pushTo,
getGroup: getGroup
getGroup: getGroup,
markdownFields: [ "description" ]
};
3 changes: 2 additions & 1 deletion lib/plugins/parser_api_success.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ function pushTo()
*/
module.exports = {
parse: parse,
pushTo: pushTo
pushTo: pushTo,
markdownFields: [ "description" ]
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apidoc",
"version": "0.5.3",
"version": "0.6.0",
"description": "RESTful web API Documentation Generator",
"author": "Peter Rottmann <[email protected]>",
"preferGlobal": true,
Expand Down
Loading

0 comments on commit 705ee7b

Please sign in to comment.