views:

105

answers:

3

Do you know if there is a 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 argumnet that will be shown in message
*/
function foo(str)
{
   alert(str);
}

I need the code in the comments to be displaied by JSDoc as code (if not sintax highlighetd, at least like preformatted or something with grey background)

Thanks.

A: 

Use

<code><pre>

....

</pre></code>

This is whats used in many official docs, and will for instance receive syntax hightlighting with some tools

Sean Kinsey
That seems odd. It is invalid HTML. Pre elements may contain code elements, but not the other way around.
David Dorward
@David, It might be that I remembered incorrectly about the order of the tags:)
Sean Kinsey
@Sean Kinsey: <pre> works.
Marco Demajo
+3  A: 

@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 argumnet that will be shown in message
 */
function foo(str)
{
   alert(str);
}
Josh Johnson
A: 

You can put any HTML in JsDoc and it will be copied out. Heres an example of what I use:

            /** The ReplaceSlang method replaces the string &quot;hi&quot; with &quot;hello&quot;.

                <script language="javascript">
                    function testFunc() {
                        alert(ReplaceSlang(prompt("Enter sample argument")));
                    }
                </script>
                <input type="button" value="Test" onclick="testFunc()" />
            @param {String} str The text to transform
            @return {String}
        */
        exports.ReplaceSlang = function(str) {
            return str.replace("hi", "hello");
        };

To make sure the button is not in the summary, add a sentence and a dot (.) before it.

You need to find some way to include your javascript file in the output of JSDoc so that they are loaded. (Your code otherwise does not exist as javascript in the output of JSDoc – you can modify the template for that : see JsPlate documentation)

Eric
I am sorry, I just realised that is not what you wanted to do. Do you mind if I leave this comment in case it helps someone ?
Eric