2016-02-11 25 views
3

我無法找到在JSDOC中記錄屬性默認值時打印空間的方法。例如: /** * @prop {string} str='String with space' - The string. */如何在jsdoc中寫屬性的默認值的空間

這將被記錄爲:

Name Type  Default  Description 
str  string '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 
      } 
     });     
    } 
}); 
+0

我把它標記爲正確的,但此刻給我一個錯誤:無法讀取property.defaultvalue = null的值;我會稍後再看看。現在我只是使用下劃線作爲空間 –

3

至少從jsdoc 3.3.0開始,你可以這樣做。

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