@@ -80,6 +80,31 @@ function removeLinks( tree ) {
8080 return found ;
8181}
8282
83+ /**
84+ * Collects existing link definitions into an object.
85+ *
86+ * @private
87+ * @param {Node } node - reference node
88+ * @returns {Object } object mapping link identifiers to `true`
89+ */
90+ function collectExistingLinks ( node ) {
91+ var existingLinks = { } ;
92+ visit ( node , 'definition' , onDefinition ) ;
93+ return existingLinks ;
94+
95+ /**
96+ * Callback invoked upon encountering a link definition.
97+ *
98+ * @private
99+ * @param {Node } definition - reference node
100+ * @returns {void }
101+ */
102+ function onDefinition ( definition ) {
103+ var identifier = definition . identifier ;
104+ existingLinks [ identifier ] = true ;
105+ }
106+ }
107+
83108
84109// MAIN //
85110
@@ -91,10 +116,12 @@ function removeLinks( tree ) {
91116* @param {File } file - virtual file
92117*/
93118function transformer ( tree , file ) {
119+ var existingLinks ;
94120 var found ;
95121 debug ( 'Processing virtual file...' ) ;
96122
97123 found = removeLinks ( tree ) ;
124+ existingLinks = collectExistingLinks ( tree ) ;
98125 visit ( tree , 'html' , insertSeeAlso ) ;
99126
100127 /**
@@ -142,7 +169,9 @@ function transformer( tree, file ) {
142169 content += '<span class="delimiter">: </span>' ;
143170 content += '<span class="description">' + description + '</span>' ;
144171 content += '\n' ;
145- links . push ( '[' + related [ i ] + ']: https://github.com/stdlib-js/stdlib' ) ;
172+ if ( ! existingLinks [ related [ i ] ] ) {
173+ links . push ( '[' + related [ i ] + ']: https://github.com/stdlib-js/stdlib' ) ;
174+ }
146175 }
147176 content += '\n' ;
148177 content += '</section>' ;
0 commit comments