@@ -10,10 +10,17 @@ var path = require('canonical-path');
1010 * @return {Object } The link information
1111 *
1212 * @property {boolean } relativeLinks Whether we expect the links to be relative to the originating doc
13+ * @property {array<function(url, title, currentDoc, ambiguousDocs) : array } disambiguators a collection of functions
14+ * that attempt to resolve ambiguous links. Each disambiguator returns a new collection of docs with
15+ * unwanted ambiguous docs removed (see moduleScopeLinkDisambiguator service for an example).
1316 */
1417module . exports = function getLinkInfo ( getDocFromAlias , encodeCodeBlock , log ) {
1518
16- return function getLinkInfoImpl ( url , title , currentDoc ) {
19+ getLinkInfoImpl . disambiguators = [ ] ;
20+
21+ return getLinkInfoImpl ;
22+
23+ function getLinkInfoImpl ( url , title , currentDoc ) {
1724 var linkInfo = {
1825 url : url ,
1926 type : 'url' ,
@@ -27,6 +34,11 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {
2734
2835 var docs = getDocFromAlias ( url , currentDoc ) ;
2936
37+ // Give each disambiguator a chance to reduce the number of ambiguous docs
38+ docs = getLinkInfoImpl . disambiguators . reduce ( function ( docs , disambiguator ) {
39+ return disambiguator ( url , title , currentDoc , docs ) ;
40+ } , docs ) ;
41+
3042 if ( ! getLinkInfoImpl . useFirstAmbiguousLink && docs . length > 1 ) {
3143
3244 linkInfo . valid = false ;
@@ -68,4 +80,5 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {
6880
6981 return linkInfo ;
7082 } ;
83+
7184} ;
0 commit comments