extract (text, beginDoc, endDoc) documon/src/extract.js 96
xpath documon.extract
file documon/src/extract.js

Extracts comments from a file into an array or mulit-dementional array when the "text" arg contains mulitple package or namepsace definitions.

Each entry in the returned array will be an object containing 3 properties

  • start : The line number that the comment started on

  • end : The line number that the comment ended on

  • data : The contents of the comment

    var myComments = extract(str);
    yields : [
    {
    start : 12,
    end : 32,
    data : "the descript"
    },
    {
    start : 12,
    end : 32,
    data : "the descript"
    }
    ]

A few things of note:

  • The data will NOT include the beginDoc, nor the endDoc strings.
  • Comment prefixing is stripped
    - * [star space]
    - tabs
    - spaces
  • Code blocks maintain indentation.
  • Splitting on package or namespace. When a single file contains mulitple references to a "package" or "namespace" comments will split into multiple arrays -- treating the single source file as being mulitple files.

Split Example:

/**
* Class A
* @package foo <-- this designates a new "page"
*&#47;

&#47;**
* Something for A
* @method something
*&#47;

&#47;**
* Class B
* @package bar <-- this designates a new "page"
*&#47;

&#47;**
* Something for B
* @method something
*&#47;

var myComments = extract(str);
yields : [
            [ // the first "page"
                { 
                    start : 12,
                    end : 32,
                    data : "Class A ... "
                },
                { 
                    start : 12,
                    end : 32,
                    data : "Something for A ..."
                },

            ],
            [ // the second "page"
                { 
                    start : 64,
                    end : 96,
                    data : "Class B ... "
                },
                { 
                    start : 128,
                    end : 142,
                    data : "Something for B ..."
                },
            ,
        ]
Parameters
text
string

the entire file as a string

beginDoc
string optional /**

The string is used to "open" a comment.

endDoc
string optional */

The string is used to "close" a comment.

Returns array

An array of comments, or multi-dimentional array oaf page comments.