Mar*_*aio 43 javascript documentation jsdoc
你知道<code />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);
}
Run Code Online (Sandbox Code Playgroud)
我需要将注释中的代码作为代码显示在JSDoc中(如果没有突出显示语法,至少像预先格式化或具有灰色背景的东西).
Sea*_*sey 37
使用
<pre><code>
....
</code></pre>
Run Code Online (Sandbox Code Playgroud)
这是许多官方文档中使用的内容,例如将使用某些工具接收语法高亮显示
Jos*_*son 35
@example http://code.google.com/p/jsdoc-toolkit/wiki/TagExample
/**
* This function does something see example below:
* @example
* 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);
}
Run Code Online (Sandbox Code Playgroud)
off*_*ker 26
Jsdoc3有一个降价插件,但默认情况下它是关闭的../node_modules/jsdoc/conf.json.EXAMPLE通过... 启用默认配置文件
"plugins": [
"plugins/markdown"
],
Run Code Online (Sandbox Code Playgroud)
...并且您对文档有很好的语法支持,包括代码.Markdown使用三个反引号(```)来划分代码块.要使用原始示例:
/**
* 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
*/
Run Code Online (Sandbox Code Playgroud)
你可以在 JSDoc 中放入任何 HTML,它会被复制出来。这是我使用的示例:
/**
* The ReplaceSlang method replaces the string "hi" with "hello".
* <script language="javascript">
* function testFunc() {
* alert(ReplaceSlang(prompt("Enter sample argument")));
* }
* </script>
* <input type="button" value="Test" onclick="testFunc()" />
* @param {String} str The text to transform
* @return {String}
*/
exports.ReplaceSlang = function(str) {
return str.replace("hi", "hello");
};
Run Code Online (Sandbox Code Playgroud)
要确保按钮不在摘要中,请在其前添加一个句子和一个点 (.)。
您需要找到某种方法将您的 javascript 文件包含在 JSDoc 的输出中,以便加载它们。(否则,您的代码在 JSDoc 的输出中不作为 javascript 存在 – 您可以为此修改模板:请参阅JsPlate 文档)
使用@example适用于大多数情况,但 HTML 保留字符需要转换为 HTML 实体:< >等等,否则 HTML 将被渲染并且不会显示为代码。
从链接的文档中:
/**
* Solves equations of the form a * x = b
* @example
* // returns 2
* globalNS.method1(5, 10);
* @example
* // returns 3
* globalNS.method(5, 15);
* @returns {Number} Returns the value of x for the equation.
*/
globalNS.method1 = function (a, b) {
return b / a;
};
Run Code Online (Sandbox Code Playgroud)
带标题的示例:
/**
* Solves equations of the form a * x = b
* @example <caption>Example usage of method1.</caption>
* // returns 2
* globalNS.method1(5, 10);
* @returns {Number} Returns the value of x for the equation.
*/
globalNS.method1 = function (a, b) {
return b / a;
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22422 次 |
| 最近记录: |