如何在jsdoc的默认属性值中写入空格

4

我无法找到在JSDOC中记录属性默认值时打印空格的方法。例如:

/** * @prop {string} str='String with space' - 带有空格的字符串。 */

这将被记录为:

Name    Type      Default       Description
str     string    'String       with space' - The string

有什么建议如何做正确的一个?
2个回答

4
至少从jsdoc 3.3.0版本开始,您可以这样做。
/**
 * @prop {string} [str=String with space] - The string.
 */

2
我并没有完整的解决方案,但今天我遇到了同样的问题并找到了一个解决办法。 :) 问题在于当前的jsdoc解析器(和正则表达式)只有在使用可选括号时才能正确地处理这个问题。而在这种情况下,我们想要一个默认值而不是可选项。
在您的模板的publish.js文件中添加以下内容。我使用“ - ”作为分隔符,因此请在描述中使用“ - ”,这样将正确地进行后处理。
data().each(function(doclet) {
    if (doclet.properties) {
        doclet.properties = doclet.properties.map(function(property) {
            var separator = " - ",
                separatorLength = separator.length;

            var defaultvalue = property.defaultvalue;
            var description = property.description;

            if( property.defaultvalue !== 'undefined' && !property.optional && description.indexOf(separator) > 0) {
                var index = description.indexOf(separator);
                defaultvalue += " " + description.substr(separatorLength, index-separatorLength);
                description = "<p>" + description.substr(index + separatorLength, description.length);
            }

            return {
                defaultvalue: defaultvalue,
                description: description,
                type: property.type,
                name: property.name
            }  
        });                  
    }
});

我标记为正确,但目前出现错误:无法读取property.defaultvalue=null的值;稍后我会查看一下。现在我只是使用下划线作为空格。 - Ardit Meti

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接