Skip to content

Commit 44d22bf

Browse files
committed
Replace marked with markdown-it. Update dependencies.
1 parent 986af3d commit 44d22bf

File tree

4 files changed

+29
-77
lines changed

4 files changed

+29
-77
lines changed

bin/apidoc

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,7 @@ var argv = nomnom
5050

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

53-
// markdown settings
54-
.option('markdown', { flag: true, 'default': true, help: 'Turn off markdown parser.' })
55-
56-
.option('marked-config', { 'default': '',
57-
help: 'Enable custom markdown parser configs. It will overwite all other marked settings.' })
58-
59-
.option('marked-gfm', { flag: true, 'default': true,
60-
help: 'Enable GitHub flavored markdown.' })
61-
62-
.option('marked-tables', { flag: true, 'default': true,
63-
help: 'Enable GFM tables. This option requires the gfm option to be true.' })
64-
65-
.option('marked-breaks', { flag: true, 'default': false,
66-
help: 'Enable GFM line breaks. This option requires the gfm option to be true.' })
67-
68-
.option('marked-pedantic', { flag: true, 'default': false,
69-
help: 'Conform to obscure parts of markdown.pl as much as possible.' })
70-
71-
.option('marked-sanitize', { flag: true, 'default': false,
72-
help: 'Sanitize the output. Ignore any HTML that has been input.' })
73-
74-
.option('marked-smartLists', { flag: true, 'default': false,
75-
help: 'Use smarter list behavior than the original markdown.' })
76-
77-
.option('marked-smartypants', { flag: true, 'default': false,
78-
help: 'Use \'smart\' typograhic punctuation for things like quotes and dashes.' })
53+
.option('markdown', { 'default': true, help: 'Turn off default markdown parser or implement a custom parser.' })
7954

8055
.parse()
8156
;
@@ -104,28 +79,6 @@ function transformToObject(filters) {
10479
return result;
10580
}
10681

107-
/**
108-
* Sets configuration for markdown
109-
*
110-
* @param {Array} argv
111-
* @returns {Object}
112-
*/
113-
function resolveMarkdownOptions(argv) {
114-
if (argv['marked-config']) {
115-
return require(path.resolve(argv['marked-config']));
116-
} else {
117-
return {
118-
gfm : argv['marked-gfm'],
119-
tables : argv['marked-tables'],
120-
breaks : argv['marked-breaks'],
121-
pedantic : argv['marked-pedantic'],
122-
sanitize : argv['marked-sanitize'],
123-
smartLists : argv['marked-smartLists'],
124-
smartypants: argv['marked-smartypants']
125-
};
126-
}
127-
}
128-
12982
var options = {
13083
excludeFilters: argv['exclude-filters'],
13184
includeFilters: argv['file-filters'],
@@ -142,8 +95,7 @@ var options = {
14295
workers : transformToObject(argv['parse-workers']),
14396
silent : argv['silent'],
14497
simulate : argv['simulate'],
145-
markdown : argv['markdown'],
146-
marked : resolveMarkdownOptions(argv)
98+
markdown : argv['markdown']
14799
};
148100

149101
if (apidoc.createDoc(options) === false) {

lib/index.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
var _ = require('lodash');
22
var apidoc = require('apidoc-core');
33
var fs = require('fs-extra');
4-
var markdown = require('marked');
54
var path = require('path');
65
var winston = require('winston');
6+
var Markdown = require('markdown-it');
77

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

@@ -15,28 +15,18 @@ var defaults = {
1515
silent : false,
1616
verbose : false,
1717
simulate: false,
18-
parse : false, // only parse and return the data, no file creation
18+
parse : false, // Only parse and return the data, no file creation.
1919
colorize: true,
20-
markdown: true,
21-
22-
marked: {
23-
gfm : true,
24-
tables : true,
25-
breaks : false,
26-
pedantic : false,
27-
sanitize : false,
28-
smartLists : false,
29-
smartypants: false
30-
}
20+
markdown: true
3121
};
3222

3323
var app = {
3424
log : {},
35-
markdown: false,
25+
markdownParser: null,
3626
options : {}
3727
};
3828

39-
// uncaughtException
29+
// Display uncaught Exception.
4030
process.on('uncaughtException', function(err) {
4131
console.error((new Date()).toUTCString() + ' uncaughtException:', err.message);
4232
console.error(err.stack);
@@ -52,18 +42,19 @@ process.on('uncaughtException', function(err) {
5242
function createDoc(options) {
5343
var api;
5444
var apidocPath = path.join(__dirname, '../');
45+
var markdownParser;
5546
var packageInfo;
5647

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

59-
// paths
50+
// Paths.
6051
options.dest = path.join(options.dest, './');
6152
options.template = path.join(options.template, './');
6253

63-
// options
54+
// Options.
6455
app.options = options;
6556

66-
// logger
57+
// Logger.
6758
app.log = new (winston.Logger)({
6859
transports: [
6960
new (winston.transports.Console)({
@@ -76,11 +67,20 @@ function createDoc(options) {
7667
]
7768
});
7869

79-
// markdown
70+
// Markdown Parser: enable / disable / use a custom parser.
8071
if(app.options.markdown === true) {
81-
app.markdown = markdown;
82-
app.markdown.setOptions(app.options.marked);
72+
markdownParser = new Markdown({
73+
breaks : false,
74+
html : true,
75+
linkify : false,
76+
typographer: false
77+
});
78+
} else if(app.options.markdown !== false) {
79+
// Include custom Parser @see MARKDOWN.md and test/fixtures/custom_markdown_parser.js
80+
Markdown = require(app.options.markdown); // Overwrite default Markdown.
81+
markdownParser = new Markdown();
8382
}
83+
app.markdownParser = markdownParser;
8484

8585
try {
8686
packageInfo = new PackageInfo(app);
@@ -94,7 +94,7 @@ function createDoc(options) {
9494
version: json.version
9595
});
9696
apidoc.setLogger(app.log);
97-
apidoc.setMarkdownParser(app.markdown);
97+
apidoc.setMarkdownParser(markdownParser);
9898
apidoc.setPackageInfos(packageInfo.get());
9999

100100
api = apidoc.parse(app.options);

lib/package_info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ PackageInfo.prototype._getHeaderFooter = function(json) {
100100
var content = fs.readFileSync(filename, 'utf8');
101101
result[key] = {
102102
title : json[key].title,
103-
content: app.markdown ? app.markdown(content) : content
103+
content: app.markdownParser ? app.markdownParser.render(content) : content
104104
};
105105
} catch (e) {
106106
throw new Error('Can not read: ' + filename + '.');

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
},
3838
"dependencies": {
3939
"apidoc-core": "~0.3.2",
40-
"fs-extra": "~0.18.1",
41-
"lodash": "~3.6.0",
42-
"marked": "~0.3.3",
40+
"fs-extra": "~0.18.2",
41+
"lodash": "~3.8.0",
42+
"markdown-it": "^4.2.1",
4343
"nomnom": "~1.8.1",
4444
"winston": "~1.0.0"
4545
},
@@ -49,7 +49,7 @@
4949
"mocha": "~2.2.4",
5050
"npm-check-updates": "^1.5.1",
5151
"path-to-regexp": "^1.0.3",
52-
"semver": "^4.3.3",
52+
"semver": "^4.3.4",
5353
"should": "~6.0.1"
5454
},
5555
"jshintConfig": {

0 commit comments

Comments
 (0)