Skip to content

Commit b89afcf

Browse files
committed
Improve linkerstack internal documentation
1 parent 211a260 commit b89afcf

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lib/output/util/linker_stack.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ function LinkerStack(config) {
5555
this.link = this.link.bind(this);
5656
}
5757

58+
/**
59+
* Given that the linker stack is a stack of functions, each of which might
60+
* be able to resolve the URL target of a given namespace, namespaceResolver
61+
* adds a function to the stack. You give it a list of comments and it
62+
* adds a function that, if it matches a namespace to a comment, runs
63+
* `resolver` on that comment's namespace in order to get a URL. This makes
64+
* it possible for themes to put each function on a separate page, or at
65+
* different anchors on the same page, and the resolver does stuff like
66+
* adding '#' in front of the namespace or turning the namespace into a URL
67+
* path.
68+
*
69+
* @param {Array<Object>} comments a list of comments
70+
* @param {Function} a method that turns a namespace into a URL
71+
* @returns {LinkerStack} returns this
72+
* @private
73+
* @example
74+
* var linkerStack = createLinkerStack(options)
75+
* .namespaceResolver(comments, function (namespace) {
76+
* var slugger = new GithubSlugger();
77+
* return '#' + slugger.slug(namespace);
78+
* });
79+
*/
5880
LinkerStack.prototype.namespaceResolver = function (comments, resolver) {
5981
var namespaces = {};
6082
walk(comments, function (comment) {
@@ -68,6 +90,15 @@ LinkerStack.prototype.namespaceResolver = function (comments, resolver) {
6890
return this;
6991
};
7092

93+
/**
94+
* Now that you've configured the LinkerStack with `namespaceResolver`
95+
* and a configuration, run it against a namepath. Might return a URL if
96+
* it can resolve a target, otherwise returns undefined.
97+
*
98+
* @param {string} namepath the namepath of a comment
99+
* @returns {string?} URL target or maybe undefined
100+
* @private
101+
*/
71102
LinkerStack.prototype.link = function (namepath) {
72103
return firstPass(this.stack, namepath);
73104
};

0 commit comments

Comments
 (0)