Skip to content

Commit

Permalink
Replace marked with markdown-it. Update dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
rottmann committed May 7, 2015
1 parent 986af3d commit 44d22bf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 77 deletions.
52 changes: 2 additions & 50 deletions bin/apidoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,7 @@ var argv = nomnom

.option('simulate', { flag: true, 'default': false, help: 'Execute but not write any file.' })

// markdown settings
.option('markdown', { flag: true, 'default': true, help: 'Turn off markdown parser.' })

.option('marked-config', { 'default': '',
help: 'Enable custom markdown parser configs. It will overwite all other marked settings.' })

.option('marked-gfm', { flag: true, 'default': true,
help: 'Enable GitHub flavored markdown.' })

.option('marked-tables', { flag: true, 'default': true,
help: 'Enable GFM tables. This option requires the gfm option to be true.' })

.option('marked-breaks', { flag: true, 'default': false,
help: 'Enable GFM line breaks. This option requires the gfm option to be true.' })

.option('marked-pedantic', { flag: true, 'default': false,
help: 'Conform to obscure parts of markdown.pl as much as possible.' })

.option('marked-sanitize', { flag: true, 'default': false,
help: 'Sanitize the output. Ignore any HTML that has been input.' })

.option('marked-smartLists', { flag: true, 'default': false,
help: 'Use smarter list behavior than the original markdown.' })

.option('marked-smartypants', { flag: true, 'default': false,
help: 'Use \'smart\' typograhic punctuation for things like quotes and dashes.' })
.option('markdown', { 'default': true, help: 'Turn off default markdown parser or implement a custom parser.' })

.parse()
;
Expand Down Expand Up @@ -104,28 +79,6 @@ function transformToObject(filters) {
return result;
}

/**
* Sets configuration for markdown
*
* @param {Array} argv
* @returns {Object}
*/
function resolveMarkdownOptions(argv) {
if (argv['marked-config']) {
return require(path.resolve(argv['marked-config']));
} else {
return {
gfm : argv['marked-gfm'],
tables : argv['marked-tables'],
breaks : argv['marked-breaks'],
pedantic : argv['marked-pedantic'],
sanitize : argv['marked-sanitize'],
smartLists : argv['marked-smartLists'],
smartypants: argv['marked-smartypants']
};
}
}

var options = {
excludeFilters: argv['exclude-filters'],
includeFilters: argv['file-filters'],
Expand All @@ -142,8 +95,7 @@ var options = {
workers : transformToObject(argv['parse-workers']),
silent : argv['silent'],
simulate : argv['simulate'],
markdown : argv['markdown'],
marked : resolveMarkdownOptions(argv)
markdown : argv['markdown']
};

if (apidoc.createDoc(options) === false) {
Expand Down
44 changes: 22 additions & 22 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var _ = require('lodash');
var apidoc = require('apidoc-core');
var fs = require('fs-extra');
var markdown = require('marked');
var path = require('path');
var winston = require('winston');
var Markdown = require('markdown-it');

var PackageInfo = require('./package_info');

Expand All @@ -15,28 +15,18 @@ var defaults = {
silent : false,
verbose : false,
simulate: false,
parse : false, // only parse and return the data, no file creation
parse : false, // Only parse and return the data, no file creation.
colorize: true,
markdown: true,

marked: {
gfm : true,
tables : true,
breaks : false,
pedantic : false,
sanitize : false,
smartLists : false,
smartypants: false
}
markdown: true
};

var app = {
log : {},
markdown: false,
markdownParser: null,
options : {}
};

// uncaughtException
// Display uncaught Exception.
process.on('uncaughtException', function(err) {
console.error((new Date()).toUTCString() + ' uncaughtException:', err.message);
console.error(err.stack);
Expand All @@ -52,18 +42,19 @@ process.on('uncaughtException', function(err) {
function createDoc(options) {
var api;
var apidocPath = path.join(__dirname, '../');
var markdownParser;
var packageInfo;

options = _.defaults({}, options, defaults);

// paths
// Paths.
options.dest = path.join(options.dest, './');
options.template = path.join(options.template, './');

// options
// Options.
app.options = options;

// logger
// Logger.
app.log = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
Expand All @@ -76,11 +67,20 @@ function createDoc(options) {
]
});

// markdown
// Markdown Parser: enable / disable / use a custom parser.
if(app.options.markdown === true) {
app.markdown = markdown;
app.markdown.setOptions(app.options.marked);
markdownParser = new Markdown({
breaks : false,
html : true,
linkify : false,
typographer: false
});
} else if(app.options.markdown !== false) {
// Include custom Parser @see MARKDOWN.md and test/fixtures/custom_markdown_parser.js
Markdown = require(app.options.markdown); // Overwrite default Markdown.
markdownParser = new Markdown();
}
app.markdownParser = markdownParser;

try {
packageInfo = new PackageInfo(app);
Expand All @@ -94,7 +94,7 @@ function createDoc(options) {
version: json.version
});
apidoc.setLogger(app.log);
apidoc.setMarkdownParser(app.markdown);
apidoc.setMarkdownParser(markdownParser);
apidoc.setPackageInfos(packageInfo.get());

api = apidoc.parse(app.options);
Expand Down
2 changes: 1 addition & 1 deletion lib/package_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ PackageInfo.prototype._getHeaderFooter = function(json) {
var content = fs.readFileSync(filename, 'utf8');
result[key] = {
title : json[key].title,
content: app.markdown ? app.markdown(content) : content
content: app.markdownParser ? app.markdownParser.render(content) : content
};
} catch (e) {
throw new Error('Can not read: ' + filename + '.');
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
},
"dependencies": {
"apidoc-core": "~0.3.2",
"fs-extra": "~0.18.1",
"lodash": "~3.6.0",
"marked": "~0.3.3",
"fs-extra": "~0.18.2",
"lodash": "~3.8.0",
"markdown-it": "^4.2.1",
"nomnom": "~1.8.1",
"winston": "~1.0.0"
},
Expand All @@ -49,7 +49,7 @@
"mocha": "~2.2.4",
"npm-check-updates": "^1.5.1",
"path-to-regexp": "^1.0.3",
"semver": "^4.3.3",
"semver": "^4.3.4",
"should": "~6.0.1"
},
"jshintConfig": {
Expand Down

0 comments on commit 44d22bf

Please sign in to comment.