Skip to content

Commit dc6b113

Browse files
committed
Change the hyperlinks to use the "xref" syntax, which is much simpler, and eliminated all the warnings from the processor
1 parent e55ade0 commit dc6b113

2 files changed

Lines changed: 18 additions & 45 deletions

File tree

‎libraries/api-documenter/src/yaml/IYamlTocFile.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,23 @@
55
* A node in the navigation hierarchy for the table of contents.
66
*/
77
export interface IYamlTocItem {
8+
/**
9+
* The title to display
10+
*/
811
name: string;
12+
13+
/**
14+
* If specified, the hyperlink will point to the API with this UID
15+
*/
16+
uid?: string;
17+
/**
18+
* IF specified, the hyperlink will point to this URL, which may be a relative URL path
19+
*/
920
href?: string;
21+
22+
/**
23+
* Child nodes in the hierarchy
24+
*/
1025
items?: IYamlTocItem[];
1126
}
1227

‎libraries/api-documenter/src/yaml/YamlGenerator.ts‎

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class YamlGenerator {
145145

146146
const tocItem: IYamlTocItem = {
147147
name: RenderingHelpers.getUnscopedPackageName(docItem.name),
148-
href: this._getRelativeUrlForDocItem(docItem, this._outputFolder)
148+
uid: this._getUid(docItem)
149149
};
150150

151151
tocItems.push(tocItem);
@@ -301,46 +301,13 @@ export class YamlGenerator {
301301
// Eventually we should introduce a warnings file
302302
console.error('==> UNRESOLVED REFERENCE: ' + JSON.stringify(args.reference));
303303
} else {
304-
// We will calculate a relativeUrl to the nearest non-embedded DocItem.
305-
// (The rest will be determined by the URL fragment.)
306-
let nonEmbeddedDocItem: DocItem = result.docItem;
307-
while (this._shouldEmbed(nonEmbeddedDocItem.kind) && nonEmbeddedDocItem.parent) {
308-
nonEmbeddedDocItem = nonEmbeddedDocItem.parent;
309-
}
310-
311-
const currentFolder: string = path.dirname(this._getYamlFilePath(containingDocItem));
312-
const relativeUrl: string = this._getRelativeUrlForDocItem(nonEmbeddedDocItem, currentFolder);
313-
314-
// Do we need to link to a fragment within the page?
315-
if (nonEmbeddedDocItem !== result.docItem) {
316-
const urlFragment: string = this._getEmbeddedUrlFragment(result.docItem);
317-
args.prefix = '[';
318-
args.suffix = `](${relativeUrl}#${urlFragment})`;
319-
} else {
320-
args.prefix = '[';
321-
args.suffix = `](${relativeUrl})`;
322-
}
323-
304+
args.prefix = '[';
305+
args.suffix = `](xref:${this._getUid(result.docItem)})`;
324306
}
325307
}
326308
});
327309
}
328310

329-
// Returns a relative URL such as "../package/MyClass"
330-
private _getRelativeUrlForDocItem(docItem: DocItem, currentFolder: string): string {
331-
const targetFilePath: string = this._getYamlFilePath(docItem);
332-
const relativePath: string = path.relative(currentFolder, targetFilePath);
333-
let relativeUrl: string = relativePath
334-
.replace(/[\\]/g, '/') // replace all backslashes with slashes
335-
.replace(/\.[^\.\\/]+$/, ''); // remove file extension
336-
337-
if (relativeUrl.substr(0, 1) !== '.') {
338-
// If the path doesn't already start with "./", then add this prefix.
339-
relativeUrl = './' + relativeUrl;
340-
}
341-
return relativeUrl;
342-
}
343-
344311
private _writeYamlFile(dataObject: {}, filePath: string, yamlMimeType: string,
345312
schema: JsonSchema|undefined): void {
346313

@@ -384,15 +351,6 @@ export class YamlGenerator {
384351
return result;
385352
}
386353

387-
/**
388-
* Calculate the HTML anchor fragment for DocItems that are embedded in a web page containing
389-
* other items.
390-
* Example: node_core_library_JsonFile_load
391-
*/
392-
private _getEmbeddedUrlFragment(docItem: DocItem): string {
393-
return this._getUid(docItem).replace(/\./g, '_'); // replace all periods with underscores
394-
}
395-
396354
private _getYamlFilePath(docItem: DocItem): string {
397355
let result: string = '';
398356

0 commit comments

Comments
 (0)