Skip to content

Commit ed78539

Browse files
committed
Merge pull request #337 from documentationjs/wooorm-rename-mdast-remark
Rename mdast to remark
2 parents 2043610 + 2198432 commit ed78539

25 files changed

+212
-341
lines changed

docs/NODE_API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Returns **string** potentially linked HTML
1818

1919
# commentsToAST
2020

21-
Given a hierarchy-nested set of comments, generate an mdast-compatible
21+
Given a hierarchy-nested set of comments, generate an remark-compatible
2222
Abstract Syntax Usable for generating Markdown output
2323

2424

@@ -583,7 +583,7 @@ split from the main function to handle hierarchially nested comments
583583

584584

585585

586-
Returns **Object** mdast-compatible AST
586+
Returns **Object** remark-compatible AST
587587

588588

589589

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,6 @@ module.exports.expandInputs = expandInputs;
183183
module.exports.formats = {
184184
html: require('./lib/output/html'),
185185
md: require('./lib/output/markdown'),
186-
mdast: require('./lib/output/markdown_ast'),
186+
remark: require('./lib/output/markdown_ast'),
187187
json: require('./lib/output/json')
188188
};

lib/commands/readme.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var fs = require('fs');
4-
var mdast = require('mdast');
4+
var remark = require('remark');
55
var inject = require('mdast-util-inject');
66
var chalk = require('chalk');
77
var disparity = require('disparity');
@@ -38,7 +38,7 @@ module.exports.parseArgs = function (yargs) {
3838

3939
function readme(documentation, parsedArgs) {
4040
var readmeOptions = parsedArgs.commandOptions;
41-
readmeOptions.format = 'mdast';
41+
readmeOptions.format = 'remark';
4242
/* eslint no-console: 0 */
4343
var log = readmeOptions.q ? function () {}
4444
: console.log.bind(console, '[documentation-readme] ');
@@ -51,7 +51,7 @@ function readme(documentation, parsedArgs) {
5151
throw err;
5252
}
5353
var readmeContent = fs.readFileSync(readmeFile, 'utf8');
54-
mdast.use(plugin, {
54+
remark.use(plugin, {
5555
section: readmeOptions.section,
5656
toInject: docsAst
5757
}).process(readmeContent, onInjected.bind(null, readmeContent));
@@ -81,8 +81,8 @@ function readme(documentation, parsedArgs) {
8181
}
8282
}
8383

84-
// wrap the inject utility as an mdast plugin
85-
function plugin(mdast, options) {
84+
// wrap the inject utility as an remark plugin
85+
function plugin(remark, options) {
8686
return function transform(targetAst, file, next) {
8787
if (!inject(options.section, targetAst, options.toInject)) {
8888
return next(new Error('Heading ' + options.section + ' not found.'));

lib/output/html.js

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,6 @@
11
'use strict';
22

3-
var walk = require('../walk'),
4-
path = require('path'),
5-
hljs = require('highlight.js');
6-
7-
/**
8-
* Create a highlighter function that transforms strings of code
9-
* into strings of HTML with highlighting tags.
10-
*
11-
* @param {boolean} auto whether to automatically detect a language
12-
* @returns {Function} highlighter function
13-
*/
14-
function highlightString(auto) {
15-
return function (example) {
16-
if (auto) {
17-
return hljs.highlightAuto(example || '').value;
18-
}
19-
return hljs.highlight('js', example || '').value;
20-
};
21-
}
22-
23-
/**
24-
* Highlights the contents of the `example` tag.
25-
* @name highlight
26-
* @param {Object} comment parsed comment
27-
* @param {Object} [options] options
28-
* @return {Object} comment with highlighted code
29-
*/
30-
function highlight(comment, options) {
31-
var hljsOptions = options.hljs || {};
32-
hljs.configure(hljsOptions);
33-
34-
if (comment.examples) {
35-
comment.examples = comment.examples.map(highlightString(hljsOptions.highlightAuto));
36-
}
37-
38-
return comment;
39-
}
3+
var path = require('path');
404

415
/**
426
* Formats documentation as HTML.
@@ -50,7 +14,6 @@ function highlight(comment, options) {
5014
*/
5115
module.exports = function makeHTML(comments, options, callback) {
5216
options = options || {};
53-
comments = walk(comments, highlight, options);
5417
var theme = require('documentation-theme-default');
5518
if (options.theme) {
5619
theme = require(path.resolve(process.cwd(), options.theme));

lib/output/markdown.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
var mdast = require('mdast'),
4-
toc = require('mdast-toc'),
3+
var remark = require('remark'),
4+
toc = require('remark-toc'),
55
markdownAST = require('./markdown_ast');
66

77
/**
@@ -15,7 +15,7 @@ var mdast = require('mdast'),
1515
* @return {undefined} calls callback
1616
*/
1717
module.exports = function (comments, opts, callback) {
18-
var processor = mdast().use(toc);
18+
var processor = remark().use(toc);
1919
markdownAST(comments, opts, function (err, ast) {
2020
var processedAST = processor.run(ast);
2121
return callback(null, processor.stringify(processedAST));

lib/output/markdown_ast.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
var mdast = require('mdast'),
1+
var remark = require('remark'),
22
u = require('unist-builder'),
33
formatType = require('documentation-theme-utils').formatType,
44
formatInlineTags = require('../format_inline_tags'),
55
hljs = require('highlight.js');
66

77
/**
8-
* Given a hierarchy-nested set of comments, generate an mdast-compatible
8+
* Given a hierarchy-nested set of comments, generate an remark-compatible
99
* Abstract Syntax Tree usable for generating Markdown output
1010
*
1111
* @param {Array<Object>} comments nested comment
@@ -25,7 +25,7 @@ function commentsToAST(comments, opts, callback) {
2525
*
2626
* @param {number} depth nesting of the comment, starting at 1
2727
* @param {Object} comment a single comment
28-
* @returns {Object} mdast-compatible AST
28+
* @returns {Object} remark-compatible AST
2929
*/
3030
function generate(depth, comment) {
3131

@@ -37,7 +37,7 @@ function commentsToAST(comments, opts, callback) {
3737
u('text', ' '),
3838
!!param.type && u('strong', formatType(param.type)),
3939
u('text', ' ')
40-
].concat(mdast.parse(formatInlineTags(param.description)).children)
40+
].concat(remark.parse(formatInlineTags(param.description)).children)
4141
.concat([
4242
!!param.default && u('paragraph', [
4343
u('text', ' (optional, default '),
@@ -74,7 +74,7 @@ function commentsToAST(comments, opts, callback) {
7474
u('strong', formatType(property.type)),
7575
u('text', ' ')
7676
]
77-
.concat(mdast.parse(formatInlineTags(property.description)).children)
77+
.concat(remark.parse(formatInlineTags(property.description)).children)
7878
.filter(Boolean)),
7979
property.properties && propertyList(property.properties)
8080
].filter(Boolean));
@@ -95,7 +95,7 @@ function commentsToAST(comments, opts, callback) {
9595
u('text', 'Returns '),
9696
u('strong', formatType(returns.type)),
9797
u('text', ' ')
98-
].concat(mdast.parse(formatInlineTags(returns.description)).children));
98+
].concat(remark.parse(formatInlineTags(returns.description)).children));
9999
});
100100
}
101101

@@ -141,10 +141,10 @@ function commentsToAST(comments, opts, callback) {
141141
})));
142142
}
143143

144-
return [u('heading', { depth: depth }, [u('text', comment.name)])]
144+
return [u('heading', { depth: depth }, [u('text', comment.name || '')])]
145145
.concat(githubLink(comment))
146146
.concat(augmentsLink(comment))
147-
.concat(mdast.parse(formatInlineTags(comment.description)).children)
147+
.concat(remark.parse(formatInlineTags(comment.description)).children)
148148
.concat(paramSection(comment))
149149
.concat(propertySection(comment))
150150
.concat(examplesSection(comment))

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
"debounce": "^1.0.0",
1818
"disparity": "^2.0.0",
1919
"doctrine": "^0.7.1",
20-
"documentation-theme-default": "2.2.1",
21-
"documentation-theme-utils": "^1.0.1",
20+
"documentation-theme-default": "2.2.3",
21+
"documentation-theme-utils": "^1.2.1",
2222
"events": "^1.1.0",
2323
"extend": "^3.0.0",
2424
"get-comments": "^1.0.1",
2525
"github-url-from-git": "^1.4.0",
26-
"highlight.js": "^8.4.0",
26+
"highlight.js": "^9.1.0",
2727
"js-yaml": "^3.3.1",
2828
"jsdoc-inline-lex": "^1.0.1",
29-
"mdast": "^2.0.0",
30-
"mdast-toc": "^1.1.0",
3129
"mdast-util-inject": "^1.1.0",
3230
"micromatch": "^2.1.6",
3331
"mime": "^1.3.4",
3432
"module-deps": "^4.0.2",
3533
"parse-filepath": "^0.6.3",
34+
"remark": "^3.0.0",
35+
"remark-toc": "^2.0.0",
3636
"remote-origin-url": "^0.4.0",
3737
"resolve": "^1.1.6",
3838
"slugg": "^0.1.2",

test/bin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ test('write to html, highlightAuto', function (t) {
259259
var result = fs.readFileSync(path.join(dstDir, 'index.html'), 'utf8');
260260
t.ok(result.indexOf('<span class="hljs-number">42</span>') > 0,
261261
'javascript is recognized by highlightjs');
262-
t.ok(result.indexOf('<span class="hljs-attr_selector">[data-foo]</span>') > 0,
262+
t.ok(result.indexOf('<span class="hljs-selector-attr">[data-foo]</span>') > 0,
263263
'css is recognized by highlightjs');
264-
t.ok(result.indexOf('<span class="hljs-attribute">data-foo</span>') > 0,
264+
t.ok(result.indexOf('<span class="hljs-attr">data-foo</span>') > 0,
265265
'html is recognized by highlightjs');
266266
t.end();
267267
}, false);

test/fixture/empty-example.output.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
"code": "/**\n * This function returns the number plus two.\n *\n * @example\n */\nfunction returnTwo() {\n return a + 2;\n}\n"
3333
},
3434
"errors": [],
35-
"examples": [null],
35+
"examples": [
36+
null
37+
],
3638
"name": "returnTwo",
3739
"kind": "function",
3840
"members": {
@@ -43,4 +45,4 @@
4345
"returnTwo"
4446
]
4547
}
46-
]
48+
]

test/fixture/empty-example.output.md.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
}
5252
]
5353
},
54-
{
55-
"lang": "javascript",
56-
"type": "code"
54+
{
55+
"lang": "javascript",
56+
"type": "code"
5757
}
5858
]
59-
}
59+
}

test/fixture/es6-import.output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ This function returns the number one.
7171

7272
**Parameters**
7373

74-
- `a` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).&lt;[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)&gt;** an array of numbers
74+
- `a` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).&lt;[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** an array of numbers
7575
- `b`
7676

7777
Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** numberone

test/fixture/es6-import.output.md.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@
10831083
},
10841084
{
10851085
"type": "text",
1086-
"value": ".&lt;"
1086+
"value": ".<"
10871087
},
10881088
{
10891089
"href": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number",
@@ -1097,7 +1097,7 @@
10971097
},
10981098
{
10991099
"type": "text",
1100-
"value": "&gt;"
1100+
"value": ">"
11011101
}
11021102
]
11031103
},

test/fixture/es6.output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ This function returns the number one.
7171

7272
**Parameters**
7373

74-
- `a` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).&lt;[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)&gt;** an array of numbers
74+
- `a` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).&lt;[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** an array of numbers
7575
- `b`
7676

7777
Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** numberone

test/fixture/es6.output.md.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@
10831083
},
10841084
{
10851085
"type": "text",
1086-
"value": ".&lt;"
1086+
"value": ".<"
10871087
},
10881088
{
10891089
"href": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number",
@@ -1097,7 +1097,7 @@
10971097
},
10981098
{
10991099
"type": "text",
1100-
"value": "&gt;"
1100+
"value": ">"
11011101
}
11021102
]
11031103
},

test/fixture/flow-types.output.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This function returns the number one.
77
- `a` **Point**
88
- `b` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
99
- `c` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)=**
10-
- `d` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)&gt;**
10+
- `d` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>**
1111
- `e` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
1212
- `f` **Named**
1313

@@ -46,7 +46,7 @@ Very Important Transform
4646

4747
**Parameters**
4848

49-
- `input` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).&lt;[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)&gt;**
49+
- `input` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).&lt;[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>**
5050
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)=** (optional, default `{}`)
5151

5252
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**

test/fixture/flow-types.output.md.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
},
194194
{
195195
"type": "text",
196-
"value": ".&lt;"
196+
"value": ".<"
197197
},
198198
{
199199
"href": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number",
@@ -207,7 +207,7 @@
207207
},
208208
{
209209
"type": "text",
210-
"value": "&gt;"
210+
"value": ">"
211211
}
212212
]
213213
},
@@ -935,7 +935,7 @@
935935
},
936936
{
937937
"type": "text",
938-
"value": ".&lt;"
938+
"value": ".<"
939939
},
940940
{
941941
"href": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String",
@@ -949,7 +949,7 @@
949949
},
950950
{
951951
"type": "text",
952-
"value": "&gt;"
952+
"value": ">"
953953
}
954954
]
955955
},

0 commit comments

Comments
 (0)