Synonyms
linkcodelinkplain
语法
🌐 Syntax
{@link namepathOrURL} [链接文本]{@link 名称路径或URL}
概述
🌐 Overview
{@link} 内联标签创建一个指向你指定的 namepath 或 URL 的链接。当你使用 {@link} 标签时,你还可以使用几种不同的格式提供链接文本。如果你没有提供任何链接文本,JSDoc 将使用 namepath 或 URL 作为链接文本。
🌐 The {@link} inline tag creates a link to the namepath or URL that you specify. When you use the
{@link} tag, you can also provide link text, using one of several different formats. If you don't
provide any link text, JSDoc uses the namepath or URL as the link text.
如果你需要链接到教程,请使用 {@tutorial} 行内标签 而不是 {@link} 标签。
🌐 If you need to link to a tutorial, use the {@tutorial} inline tag instead
of the {@link} tag.
链接格式
🌐 Link formatting
默认情况下,{@link} 会生成标准的 HTML 锚点标签。然而,你可能希望将某些链接以等宽字体呈现,或者指定单个链接的格式。你可以使用以下 {@link} 标签的同义词来控制链接的格式:
🌐 By default, {@link} generates standard HTML anchor tags. However, you may prefer to render certain
links in a monospace font, or to specify the format of individual links. You can use the following
synonyms for the {@link} tag to control the formatting of links:
{@linkcode}:强制链接文本使用等宽字体。{@linkplain}:强制链接文本显示为普通文本,不使用等宽字体。
你还可以在 JSDoc 的配置文件中设置以下选项之一;有关更多详情,请参阅 配置 JSDoc:
🌐 You can also set one of the following options in JSDoc's configuration file; see Configuring JSDoc for more details:
templates.cleverLinks:当设置为true时,URL 链接使用普通文本,代码链接使用等宽字体。templates.monospaceLinks:当设置为true时,所有链接都使用等宽字体,除了使用{@linkplain}标签创建的链接。
注意:虽然默认的 JSDoc 模板可以正确渲染所有这些标签,但其他模板可能无法识别 {@linkcode} 和 {@linkplain} 标签。此外,其他模板可能会忽略链接渲染的配置选项。
示例
🌐 Examples
以下示例展示了为 {@link} 标签提供链接文本的所有方法:
🌐 The following example shows all of the ways to provide link text for the {@link} tag:
/**
* See {@link MyClass} and [MyClass's foo property]{@link MyClass#foo}.
* Also, check out {@link http://www.google.com|Google} and
* {@link https://github.com GitHub}.
*/
function myFunction() {}
默认情况下,上面的示例会生成类似于以下内容的输出:
🌐 By default, the example above produces output similar to the following:
See <a href="MyClass.html">MyClass</a> and <a href="MyClass.html#foo">MyClass's foo
property</a>. Also, check out <a href="http://www.google.com">Google</a> and
<a href="https://github.com">GitHub</a>.
如果配置属性 templates.cleverLinks 设置为 true,上面的示例将生成以下输出:
🌐 If the configuration property templates.cleverLinks were set to true, the example above would
produce the following output:
See <a href="MyClass.html"><code>MyClass</code></a> and <a href="MyClass.html#foo">
<code>MyClass's foo property</code></a>. Also, check out
<a href="http://www.google.com">Google</a> and <a href="https://github.com">GitHub</a>.