@@ -80,6 +80,31 @@ function removeLinks( tree ) {
80
80
return found ;
81
81
}
82
82
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
+
83
108
84
109
// MAIN //
85
110
@@ -91,10 +116,12 @@ function removeLinks( tree ) {
91
116
* @param {File } file - virtual file
92
117
*/
93
118
function transformer ( tree , file ) {
119
+ var existingLinks ;
94
120
var found ;
95
121
debug ( 'Processing virtual file...' ) ;
96
122
97
123
found = removeLinks ( tree ) ;
124
+ existingLinks = collectExistingLinks ( tree ) ;
98
125
visit ( tree , 'html' , insertSeeAlso ) ;
99
126
100
127
/**
@@ -142,7 +169,9 @@ function transformer( tree, file ) {
142
169
content += '<span class="delimiter">: </span>' ;
143
170
content += '<span class="description">' + description + '</span>' ;
144
171
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
+ }
146
175
}
147
176
content += '\n' ;
148
177
content += '</section>' ;
0 commit comments