简体   繁体   English

JSDoc评论中的JSDoc评论

[英]JSDoc comment within a JSDoc comment

I'm giving code examples with JSDoc comments which also contain JSDoc comments, how can I escape the nested JSDoc comment without breaking the outer comment? 我在给JSDoc注释的代码示例也包含JSDoc注释,如何在不破坏外部注释的情况下转义嵌套的JSDoc注释?

I'm using Version 3.3.0-beta3 我使用的是版本3.3.0-beta3

Example: 例:

 /**
  * @example
  * /**
  *  * Description.
  *  * @alias ...
  *  * @extends ...
  *  * @constructor
  *  */
  * function Something() {
  *     ...
  * }
  * ...
  */
 function MyFun() {
 ...

The nested */ will of course break the comment. 嵌套的*/ will当然会破坏评论。 An extra space will prevent this * / or a *\\/ , which then - of course - shows up in the JSDoc doc, which I don't want. 额外的空间会阻止这个* /或a *\\/ ,然后 - 当然 - 出现在JSDoc文档中,我不想要。

Is there any way to escape this so the generated JSDoc will look like the proper code? 有没有办法逃避这个,所以生成的JSDoc看起来像正确的代码?

I'm not aware of a way to escape this but you could write a simple plugin which does 我不知道如何逃避这个,但你可以编写一个简单的插件

exports.handlers = {
    newDoclet : function(doclet) {
        if(doclet.example){
            doclet.example = doclet.example.replace(/*\//g,'*/');
        }
    }
};

Note that I have not tried this out but it should do the trick. 请注意,我没有尝试过,但应该这样做。

If you're willing to have your examples in Markdown code blocks instead of JSDoc @example blocks, you can enable the Markdown plugin as described here and use HTML character references to escape one or more of the problematic nested comment characters, as in the following: 如果您愿意在Markdown代码块而不是JSDoc @example块中使用示例,则可以按照此处所述启用Markdown插件,并使用HTML字符引用来转义一个或多个有问题的嵌套注释字符,如下所示:

/**
 * Example:
 *
 *     /**
 *      * Description.
 *      * @alias ...
 *      * @extends ...
 *      * @constructor
 *      */
 *     function Something() {
 *         ...
 *     }
 *     ...
 */
function MyFun() {
...

This has been tested to work with JSDoc 3.3.2. 已经过测试,可以使用JSDoc 3.3.2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM