JSDoc 在文档中添加真实代码
你知道 JSDoc 中是否有某种 标签吗?我需要在我的文档中添加如下代码:
/**
* This function does something see example below:
*
* var x = foo("test"); //it will show "test" message
*
* @param {string} str: string argument that will be shown in message
*/
function foo(str)
{
alert(str);
}
我需要将注释中的代码由 JSDoc 显示为代码(如果没有突出显示语法,至少像预格式化或带有灰色背景的东西)。
Do you know if there is some sort of <code />
tag in JSDoc? I need to add pieces of code in my documentation like this:
/**
* This function does something see example below:
*
* var x = foo("test"); //it will show "test" message
*
* @param {string} str: string argument that will be shown in message
*/
function foo(str)
{
alert(str);
}
I need the code in the comments to be displayed by JSDoc as code (if not syntax highlighted, at least like pre-formatted or something with grey background).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
@example
http://code.google.com/ p/jsdoc-toolkit/wiki/TagExample@example
http://code.google.com/p/jsdoc-toolkit/wiki/TagExample使用
这是许多官方文档中使用的内容,例如可以使用某些工具接收语法高亮显示
Use
This is whats used in many official docs, and will for instance receive syntax hightlighting with some tools
Jsdoc3 有一个 markdown 插件,但默认是关闭的。通过……启用默认配置文件
./node_modules/jsdoc/conf.json.EXAMPLE
,您就可以对文档(包括代码)提供良好的语法支持。 Markdown 使用三个反引号 (
```
) 来划分代码块。要使用原始示例:Jsdoc3 has a markdown plugin but it is turned off by default. Enable it the default config file
./node_modules/jsdoc/conf.json.EXAMPLE
via ...... and you have nice syntax support for docs, including for code. Markdown uses three backticks (
```
) to demarcate code blocks. For to use the original example:您可以将任何 HTML 放入 JSDoc 中,它将被复制出来。这是我使用的示例:
要确保该按钮不在摘要中,请在其前面添加一个句子和一个点 (.)。
您需要找到某种方法将 javascript 文件包含在 JSDoc 的输出中,以便加载它们。 (否则您的代码在 JSDoc 的输出中不会以 javascript 形式存在 - 您可以修改模板:请参阅 JsPlate 文档)
You can put any HTML in JSDoc and it will be copied out. Heres an example of what I use:
To make sure the button is not in the summary, add a sentence and a dot (.) before it.
You need to find some way to include your javascript file in the output of JSDoc so that they are loaded. (Your code otherwise does not exist as javascript in the output of JSDoc – you can modify the template for that : see JsPlate documentation)
使用 @example 适用于大多数情况,但 HTML 保留字符需要转换为 HTML 实体:
<
>
等等,否则 HTML 将被渲染而不是显示为代码。来自链接的文档:
带有标题的示例:
Using @example works for most cases, but HTML reserved characters need to be translated to HTML entities:
<
>
and so on, otherwise the HTML will be rendered and not displayed as code.From the linked documentation:
An example with a caption:
对于 jsdoc3
似乎工作得很好。它还使代码保持内联,同时添加...
For jsdoc3
<code>...</code>
seems to work just fine. It also keeps the code inline while adding in<pre>
creates a paragraph (which is what it should do anyways). Browser support seems to be ok so I don't see any reason to not use it.