JSDoc adding real code in documentation

Marco Demaio picture Marco Demaio · Jun 2, 2010 · Viewed 27.2k times · Source

Do you know if there is some sort of <code /> tag in JSDoc? I need to add pieces of code in my documentation like this:

/**
 * 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);
}

I need the code in the comments to be displayed by JSDoc as code (if not syntax highlighted, at least like pre-formatted or something with grey background).

Answer

Josh Johnson picture Josh Johnson · Jul 13, 2010

@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);
}