Skip to content

Commit e3b0406

Browse files
committed
Use reference links in Markdown.
Fixes documentationjs#948. This approach might be problematic when inserting markdown under a readme heading if the readme already has link references with conflicting ID’s.
1 parent 487336f commit e3b0406

File tree

4 files changed

+73
-40
lines changed

4 files changed

+73
-40
lines changed

docs/NODE_API.md

+61-35
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
### Table of Contents
44

5-
- [lint](#lint)
6-
- [build](#build)
7-
- [formats](#formats)
8-
- [formats.html](#formatshtml)
9-
- [formats.markdown](#formatsmarkdown)
10-
- [formats.json](#formatsjson)
5+
- [lint][1]
6+
- [build][2]
7+
- [formats][3]
8+
- [formats.html][4]
9+
- [formats.markdown][5]
10+
- [formats.json][6]
1111

1212
## lint
1313

@@ -17,18 +17,18 @@ of lint information intended for human-readable output.
1717

1818
**Parameters**
1919

20-
- `indexes` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)> | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** files to process
21-
- `args` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** args
22-
- `args.external` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** a string regex / glob match pattern
20+
- `indexes` **([Array][7]<[string][8]> | [string][8])** files to process
21+
- `args` **[Object][9]** args
22+
- `args.external` **[Array][7]<[string][8]>** a string regex / glob match pattern
2323
that defines what external modules will be whitelisted and included in the
2424
generated documentation.
25-
- `args.shallow` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether to avoid dependency parsing
25+
- `args.shallow` **[boolean][10]** whether to avoid dependency parsing
2626
even in JavaScript code. (optional, default `false`)
27-
- `args.inferPrivate` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** a valid regular expression string
27+
- `args.inferPrivate` **[string][8]?** a valid regular expression string
2828
to infer whether a code element should be private, given its naming structure.
2929
For instance, you can specify `inferPrivate: '^_'` to automatically treat
3030
methods named like `_myMethod` as private.
31-
- `args.extension` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)?** treat additional file extensions
31+
- `args.extension` **([string][8] \| [Array][7]<[string][8]>)?** treat additional file extensions
3232
as JavaScript, extending the default set of `js`, `es6`, and `jsx`.
3333

3434
**Examples**
@@ -44,7 +44,7 @@ documentation.lint('file.js').then(lintOutput => {
4444
});
4545
```
4646

47-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** promise with lint results
47+
Returns **[Promise][11]** promise with lint results
4848

4949
## build
5050

@@ -53,25 +53,25 @@ comments, given a root file as a path.
5353

5454
**Parameters**
5555

56-
- `indexes` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)> | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** files to process
57-
- `args` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** args
58-
- `args.external` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** a string regex / glob match pattern
56+
- `indexes` **([Array][7]<[string][8]> | [string][8])** files to process
57+
- `args` **[Object][9]** args
58+
- `args.external` **[Array][7]<[string][8]>** a string regex / glob match pattern
5959
that defines what external modules will be whitelisted and included in the
6060
generated documentation.
61-
- `args.shallow` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether to avoid dependency parsing
61+
- `args.shallow` **[boolean][10]** whether to avoid dependency parsing
6262
even in JavaScript code. (optional, default `false`)
63-
- `args.order` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))>** optional array that
63+
- `args.order` **[Array][7]<([string][8] \| [Object][9])>** optional array that
6464
defines sorting order of documentation (optional, default `[]`)
65-
- `args.access` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** an array of access levels
65+
- `args.access` **[Array][7]<[string][8]>** an array of access levels
6666
to output in documentation (optional, default `[]`)
67-
- `args.hljs` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** hljs optional args
68-
- `args.hljs.highlightAuto` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** hljs automatically detect language (optional, default `false`)
69-
- `args.hljs.languages` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)?** languages for hljs to choose from
70-
- `args.inferPrivate` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** a valid regular expression string
67+
- `args.hljs` **[Object][9]?** hljs optional args
68+
- `args.hljs.highlightAuto` **[boolean][10]** hljs automatically detect language (optional, default `false`)
69+
- `args.hljs.languages` **[Array][7]?** languages for hljs to choose from
70+
- `args.inferPrivate` **[string][8]?** a valid regular expression string
7171
to infer whether a code element should be private, given its naming structure.
7272
For instance, you can specify `inferPrivate: '^_'` to automatically treat
7373
methods named like `_myMethod` as private.
74-
- `args.extension` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)?** treat additional file extensions
74+
- `args.extension` **([string][8] \| [Array][7]<[string][8]>)?** treat additional file extensions
7575
as JavaScript, extending the default set of `js`, `es6`, and `jsx`.
7676

7777
**Examples**
@@ -89,7 +89,7 @@ documentation.build(['index.js'], {
8989
});
9090
```
9191

92-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** results
92+
Returns **[Promise][11]** results
9393

9494
## formats
9595

@@ -104,9 +104,9 @@ Formats documentation as HTML.
104104

105105
**Parameters**
106106

107-
- `comments` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Comment](https://developer.mozilla.org/docs/Web/API/Comment/Comment)>** parsed comments
108-
- `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options that can customize the output
109-
- `config.theme` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of a module used for an HTML theme. (optional, default `'default_theme'`)
107+
- `comments` **[Array][7]<[Comment][12]>** parsed comments
108+
- `config` **[Object][9]** Options that can customize the output
109+
- `config.theme` **[string][8]** Name of a module used for an HTML theme. (optional, default `'default_theme'`)
110110

111111
**Examples**
112112

@@ -122,17 +122,17 @@ documentation.build(['index.js'])
122122
});
123123
```
124124

125-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>>** Promise with results
125+
Returns **[Promise][11]<[Array][7]<[Object][9]>>** Promise with results
126126

127127
## formats.markdown
128128

129129
Formats documentation as
130-
[Markdown](http://daringfireball.net/projects/markdown/).
130+
[Markdown][13].
131131

132132
**Parameters**
133133

134-
- `comments` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>** parsed comments
135-
- `args` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options that can customize the output
134+
- `comments` **[Array][7]<[Object][9]>** parsed comments
135+
- `args` **[Object][9]** Options that can customize the output
136136

137137
**Examples**
138138

@@ -148,15 +148,15 @@ documentation.build(['index.js'])
148148
});
149149
```
150150

151-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** a promise of the eventual value
151+
Returns **[Promise][11]<[string][8]>** a promise of the eventual value
152152

153153
## formats.json
154154

155155
Formats documentation as a JSON string.
156156

157157
**Parameters**
158158

159-
- `comments` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Comment](https://developer.mozilla.org/docs/Web/API/Comment/Comment)>** parsed comments
159+
- `comments` **[Array][7]<[Comment][12]>** parsed comments
160160

161161
**Examples**
162162

@@ -172,4 +172,30 @@ documentation.build(['index.js'])
172172
});
173173
```
174174

175-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
175+
Returns **[Promise][11]<[string][8]>**
176+
177+
[1]: #lint
178+
179+
[2]: #build
180+
181+
[3]: #formats
182+
183+
[4]: #formatshtml
184+
185+
[5]: #formatsmarkdown
186+
187+
[6]: #formatsjson
188+
189+
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
190+
191+
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
192+
193+
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
194+
195+
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
196+
197+
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
198+
199+
[12]: https://developer.mozilla.org/docs/Web/API/Comment/Comment
200+
201+
[13]: http://daringfireball.net/projects/markdown/

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"read-pkg-up": "^3.0.0",
4242
"remark": "^9.0.0",
4343
"remark-html": "7.0.0",
44+
"remark-reference-links": "^4.0.1",
4445
"remark-toc": "^5.0.0",
4546
"remote-origin-url": "0.4.0",
4647
"shelljs": "^0.8.1",

src/output/markdown_ast.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const u = require('unist-builder');
44
const remark = require('remark');
55
const mergeConfig = require('../merge_config');
66
const toc = require('remark-toc');
7+
const links = require('remark-reference-links');
78
const hljs = require('highlight.js');
89
const GithubSlugger = require('github-slugger');
910
const LinkerStack = require('./util/linker_stack');
@@ -374,11 +375,10 @@ function buildMarkdownAST(
374375
)
375376
);
376377

377-
if (config.markdownToc) {
378-
root = remark()
379-
.use(toc, { tight: true })
380-
.run(root);
381-
}
378+
const pluginRemark = remark();
379+
if (config.markdownToc) pluginRemark.use(toc, { tight: true });
380+
pluginRemark.use(links);
381+
root = pluginRemark.run(root);
382382

383383
return Promise.resolve(root);
384384
}

yarn.lock

+6
Original file line numberDiff line numberDiff line change
@@ -5030,6 +5030,12 @@ remark-parse@^5.0.0:
50305030
vfile-location "^2.0.0"
50315031
xtend "^4.0.1"
50325032

5033+
remark-reference-links@^4.0.1:
5034+
version "4.0.1"
5035+
resolved "https://registry.yarnpkg.com/remark-reference-links/-/remark-reference-links-4.0.1.tgz#021aed1c55c187d712b3c76d0057bf510d300ba7"
5036+
dependencies:
5037+
unist-util-visit "^1.0.0"
5038+
50335039
remark-slug@^5.0.0:
50345040
version "5.0.0"
50355041
resolved "https://registry.yarnpkg.com/remark-slug/-/remark-slug-5.0.0.tgz#9de71fcdc2bfae33ebb4a41eb83035288a829980"

0 commit comments

Comments
 (0)