Skip to content

Commit ffec98a

Browse files
authored
Merge pull request #1 from octogonz/octogonz/see-tag
2 parents 644ea51 + cdf8640 commit ffec98a

File tree

3 files changed

+78
-14
lines changed

3 files changed

+78
-14
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/tsdoc",
5+
"comment": "Add support for `@see` tag",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/tsdoc",
10+
"email": "hansbergren@gmail.com"
11+
}

playground/src/DocHtmlView.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,43 @@ export class DocHtmlView extends React.Component<IDocHtmlViewProps> {
7272
);
7373
}
7474

75+
const exampleBlocks: tsdoc.DocBlock[] = docComment.customBlocks.filter(x => x.blockTag.tagNameWithUpperCase
76+
=== tsdoc.StandardTags.example.tagNameWithUpperCase);
77+
78+
let exampleNumber: number = 1;
79+
for (const exampleBlock of exampleBlocks) {
80+
const heading: string = exampleBlocks.length > 1 ? `Example ${exampleNumber}` : 'Example';
81+
82+
outputElements.push(
83+
<React.Fragment key='seeAlso'>
84+
<h2 className='doc-heading'>{heading}</h2>
85+
{ this._renderContainer(exampleBlock.content) }
86+
</React.Fragment>
87+
);
88+
89+
++exampleNumber;
90+
}
91+
92+
if (docComment.seeBlocks.length > 0) {
93+
const listItems: React.ReactNode[] = [];
94+
for (const seeBlock of docComment.seeBlocks) {
95+
listItems.push(
96+
<li key={`item_${listItems.length}`}>
97+
{ this._renderContainer(seeBlock.content) }
98+
</li>
99+
);
100+
}
101+
102+
outputElements.push(
103+
<React.Fragment key='seeAlso'>
104+
<h2 className='doc-heading'>See Also</h2>
105+
<ul>
106+
{listItems}
107+
</ul>
108+
</React.Fragment>
109+
);
110+
}
111+
75112
const modifierTags: ReadonlyArray<tsdoc.DocBlockTag> = docComment.modifierTagSet.nodes;
76113

77114
if (modifierTags.length > 0) {

tsdoc/src/details/StandardTags.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ export class StandardTags {
125125
* separate NPM package.
126126
*
127127
* What gets copied
128-
*
129-
* The `@inheritDoc` tag does not copy the entire comment body. Only the following
128+
*
129+
* The `@inheritDoc` tag does not copy the entire comment body. Only the following
130130
* components are copied:
131131
* - summary section
132132
* - `@remarks` block
133133
* - `@params` blocks
134134
* - `@typeParam` blocks
135135
* - `@returns` block
136-
* Other tags such as `@defaultValue` or `@example` are not copied, and need to be
136+
* Other tags such as `@defaultValue` or `@example` are not copied, and need to be
137137
* explicitly included after the `@inheritDoc` tag.
138138
*
139139
* TODO: The notation for API item references is still being standardized. See this issue:
@@ -331,26 +331,42 @@ export class StandardTags {
331331
/**
332332
* (Extended)
333333
*
334-
* Used to document another symbol or resource that may be related to the current item being documented.
334+
* Used to build a list of references to an API item or other resource that may be related to the
335+
* current item.
335336
*
336337
* @remarks
337338
*
338339
* For example:
339340
*
340341
* ```ts
341342
* /**
342-
* * Link to the bar function.
343-
* * @see {@link bar}
343+
* * Parses a string containing a Uniform Resource Locator (URL).
344+
* * @see {@link ParsedUrl} for the returned data structure
345+
* * @see {@link https://tools.ietf.org/html/rfc1738|RFC 1738}
346+
* * for syntax
347+
* * @see your developer SDK for code samples
348+
* * @param url - the string to be parsed
349+
* * @returns the parsed result
344350
* &#42;/
345-
* function foo() {}
346-
347-
* // Use the inline {@link} tag to include a link within a free-form description.
348-
* /**
349-
* * @see {@link foo} for further information.
350-
* * @see {@link http://github.com|GitHub}
351-
* &#42;/
352-
* function bar() {}
351+
* function parseURL(url: string): ParsedUrl;
352+
* ```
353+
*
354+
* `@see` is a block tag. Each block becomes an item in the list of references. For example, a documentation
355+
* system might render the above blocks as follows:
356+
*
357+
* ```markdown
358+
* `function parseURL(url: string): ParsedUrl;`
359+
*
360+
* Parses a string containing a Uniform Resource Locator (URL).
361+
*
362+
* ## See Also
363+
* - ParsedUrl for the returned data structure
364+
* - RFC 1738 for syntax
365+
* - your developer SDK for code samples
353366
* ```
367+
*
368+
* NOTE: JSDoc attempts to automatically hyperlink the text immediately after `@see`. Because this is ambiguous
369+
* with plain text, TSDoc instead requires an explicit `{@link}` tag to make hyperlinks.
354370
*/
355371
public static readonly see: TSDocTagDefinition = StandardTags._defineTag({
356372
tagName: '@see',

0 commit comments

Comments
 (0)