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

Javascript 如何在jsdoc属性的默认值中写入空格,javascript,jsdoc,jsdoc3,Javascript,Jsdoc,Jsdoc3,在JSDOC中记录属性默认值时,我找不到打印空间的方法。例子: /** *@prop{string}str='string with space'-字符串。 */ 这将记录为: Name Type Default Description str string 'String with space' - The string 有没有关于如何做正确的建议?我不太了解解决方案,但今天我面对同样的问题,找到了解决办法。:)问题是,当前的jsdoc解

在JSDOC中记录属性默认值时,我找不到打印空间的方法。例子:
/**
*@prop{string}str='string with space'-字符串。
*/

这将记录为:

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

有没有关于如何做正确的建议?

我不太了解解决方案,但今天我面对同样的问题,找到了解决办法。:)问题是,当前的jsdoc解析器(和regex)只有在使用可选括号时才能正确处理这个问题。在这种情况下,我们希望默认值不是可选的

在模板的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
            }  
        });                  
    }
});
data()。每个函数(doclet){
if(doclet.properties){
doclet.properties=doclet.properties.map(函数(属性){
变量分隔符=“-”,
分离器长度=分离器长度;
var defaultvalue=property.defaultvalue;
变量说明=property.description;
if(property.defaultvalue!='undefined'&&&!property.optional&&description.indexOf(分隔符)>0){
var index=description.indexOf(分隔符);
defaultvalue+=“”+description.substr(分隔符长度、索引分隔符长度);
description=“”+description.substr(索引+分隔符长度,description.length);
}
返回{
defaultvalue:defaultvalue,
描述:描述,
类型:property.type,
名称:property.name
}  
});                  
}
});

至少从jsdoc 3.3.0开始,您可以这样做

/**
 * @prop {string} [str=String with space] - The string.
 */

我将其标记为正确,但此时给我一个错误:无法读取属性的值。defaultvalue=null;我稍后会看一看。现在我只使用下划线作为空格