Comment Parser API
load
Load and parse file contents.
When a callback function is given it is added as a listener for the error and end events on the source file stream.
Returns the parser stream.
fileString path.optsObject processing options.cbFunction callback function.
parse
parse(buffer[, opts][, cb])
Parse a string or buffer.
When a callback function is given it is added as a listener for the error and finish events on the parser stream.
Returns the parser stream.
bufferString|Buffer input data.optsObject processing options.cbFunction callback function.
Collator
Collate comments and source content into a stream.
Allows for writing files that contains only content, only comments or both content and comments. By default this stream will pass through comments and content.
To disable content from the stream (comments only) use:
To disable comments from the stream (source content only) use:
When the buffer option is set all output is buffered into
the buffer property as a string, listen for the finish event before
attempting to access the buffer contents.
optsObject stream options.
Options
contentBoolean push content chunks to the stream.commentBoolean push comment chunks to the stream.bufferBoolean buffer output.stringifyBoolean convert output to JSON strings.indentNumber number of spaces to indent JSON.
Comment
Parse comments from an array of lines.
When a comment is parsed an object is pushed to the stream
with an array of lines, the rule for the comment and the
start and end line numbers.
When a content block is encountered a string is pushed for inline content (between comments on a single-line or trailing content), otherwise an array of lines is pushed.
optsObject stream options.
Options
rulesArray|Function defines the comment rules.optionsObject to pass to therulesfunction.
Parser
Comment and tag parser, parses comment description and tags.
optsObject stream options.
Options
tagObject defines the tag patterns, see tagdottedBoolean parse dotted names in tags.
Events
commentwhen a comment has been parsed.contentwhen a content chunk is received.
.stringify
Parser.prototype.stringify(indent, comment)
Creates a stream that transforms to newline-delimited JSON, the created stream is piped from this parser.
Returns the stringify stream.
indentNumber the number of spaces to indent the JSON.commentBoolean only include comment output.
rule
A language rule is an object containing the open, close and strip
functions.
The open and close functions are passed the current line and should
return the exec match for the pattern.
The strip function is passed an array of lines for the entire comment and should remove comment meta characters from all lines.
defaults
Creates the default language rules for the C family of languages.
By default recognises continuous lines with // comments and terminated
multi-line comments starting with ``.
To include /* comments as well set the greedy option:
Returns list of language rules.
optsObject processing options.
Options
multiObject multi-line rule configuration.singleObject single-line rule configuration.
#multi
Creates a multi-line rule, when no options are given creates the default C family multi-line rule.
Returns multi-line language rule.
optsObject processing options.
Options
greedyBoolean include/*comments.startRegExp comment start pattern.endRegExp comment end pattern.leadRegExp remove leading meta characters that match.trailRegExp remove trailing meta characters that match.openFunction override default open function.closeFunction override default close function.stripFunction override default strip function.
#single
Creates a single-line rule, when no options are given creates the default C family single-line rule.
Returns single-line language rule.
optsObject processing options.
Options
markRegExp sub pattern.startRegExp comment start pattern.endRegExp comment end pattern.leadRegExp remove leading meta characters that match.trailRegExp remove trailing meta characters that match.openFunction override default open function.closeFunction override default close function.stripFunction override default strip function.
Tag
Defines the patterns and functions that perform the tag parsing.
Create a custom tag definition if you wanted to use an alternative
syntax or prefer something other than @ as the tag identifier.
The generic syntax for tags is: @id {type[=value]} name description;
everything but the tag id is considered optional.
Which when given: @property {String=mkdoc} [nickname] user will expand
to a tag object such as:
{ id: 'property', type: 'String', value: 'mkdoc', name: 'nickname', description: 'user', optional: true }
See the tag parser.
rule
Pattern that collects tag lines.
unescape
Pattern that unescapes tag sequences after parsing.
pattern
Pattern that collects tag component parts.
optional
Pattern that determines optionality.
whitespace
Pattern that determines how to strip leading whitespace from lines.
By default will match one or two spaces, depending upon your comment style you should adjust this so that whitespace is preserved as intended.
parse
Parses the component parts of a tag definition.
This will add the id, type, name and description
fields to the input tag argument.
lineString current line being parsed.tagObject target for parsed data.
language
Contains utilities for testing whether a language id is valid, loading language packs and finding language identifiers by file extension.
find
Find a language pack identifier by file extension.
File extensions must not include the leading period.
Returns language pack identifier if found.
extString file extension.
exists
Test whether a language exists by identifier.
Returns whether the language pack exists.
idString language pack identifier.
load
Load a language pack by identifier.
idString language pack identifier.
Throws
Errorif the language pack does not exist.
actionscript
Creates an array of language rules for actionscript files.
Recognises continuous lines with // comments and terminated
multi-line comments starting with ``.
See the default settings.
Returns list of language rules.
optsObject processing options.
c
Creates an array of language rules for C files.
Recognises terminated multi-line comments starting with /*.
See the default settings.
Returns list of language rules.
optsObject processing options.
Options
greedyBoolean=true disable to use `` comments only.
coffeescript
Creates an array of language rules for coffeescript files.
Recognises continuous blocks of lines beginning with # and multi-line
comments delimited with ###.
Returns list of language rules.
optsObject processing options.
conf
Creates an array of language rules for conf files.
Recognises continuous blocks of lines beginning with #.
See the shell language.
Returns list of language rules.
optsObject processing options.
cpp
Creates an array of language rules for C++ files.
Recognises continuous lines with // comments and terminated
multi-line comments starting with ``.
See the default settings.
Returns list of language rules.
optsObject processing options.
Options
greedyBoolean include/*comments.
css
Creates an array of language rules for css files.
Recognises terminated multi-line comments starting with /*.
See the c language.
Returns list of language rules.
optsObject processing options.
erlang
Creates an array of language rules for erlang files.
Recognises continuous blocks of lines beginning with %.
Returns list of language rules.
optsObject processing options.
go
Creates an array of language rules for go files.
Recognises continuous lines with // comments and terminated
multi-line comments starting with ``.
See the default settings.
Returns list of language rules.
optsObject processing options.
groovy
Creates an array of language rules for groovy files.
Recognises continuous lines with // comments and terminated
multi-line comments starting with ``.
See the default settings.
Returns list of language rules.
optsObject processing options.
html
Creates an array of language rules for HTML files.
Recognises multi-line comments started with <!-- and terminated
with -->.
Returns list of language rules.
optsObject processing options.
ini
Creates an array of language rules for ini files.
Recognises continuous blocks of lines beginning with ;.
Returns list of language rules.
optsObject processing options.
Options
markRegExp sub pattern.trailRegExp pattern to strip trailing meta characters.
jade
Creates an array of language rules for jade files.
Recognises continuous blocks starting with //- or //.
Returns list of language rules.
optsObject processing options.
java
Creates an array of language rules for java files.
Recognises continuous lines with // comments and terminated
multi-line comments starting with ``.
See the default settings.
Returns list of language rules.
optsObject processing options.
javascript
Creates an array of language rules for javascript files.
Recognises continuous lines with // comments and terminated
multi-line comments starting with ``.
See the default settings.
Returns list of language rules.
optsObject processing options.
less
Creates an array of language rules for less files.
Recognises terminated multi-line comments starting with /* and
continuous blocks of single-line comments beginning with //.
See the css language.
Returns list of language rules.
optsObject processing options.
markdown
Creates an array of language rules for markdown files.
Recognises multi-line comments started with <!-- and terminated
with -->.
See the html language.
Returns list of language rules.
optsObject processing options.
Languages
Collection of language packs.
Default language pack used is the cpp language.
pandoc
Creates an array of language rules for pandoc files.
Recognises multi-line comments starting with <!-- or <!--- and
terminated with -->, extends the html language.
See the pandoc website.
Returns list of language rules.
optsObject processing options.
php
Creates an array of language rules for php files.
Recognises continuous lines with // comments and terminated
multi-line comments starting with ``.
See the default settings.
Returns list of language rules.
optsObject processing options.
pi
Creates an array of language rules for SGML/XML processing instructions.
Recognises multi-line comments started with <? and terminated
with ?>.
Returns list of language rules.
optsObject processing options.
processing
Creates an array of language rules for processing files.
Recognises continuous lines with // comments and terminated
multi-line comments starting with ``.
See the default settings.
Returns list of language rules.
optsObject processing options.
properties
Creates an array of language rules for Java properties files.
Recognises continuous blocks of lines beginning with #.
See the shell language.
Returns list of language rules.
optsObject processing options.
python
Creates an array of language rules for python files.
Recognises continuous blocks of lines beginning with # and multi-line
comments delimited with """.
Returns list of language rules.
optsObject processing options.
ruby
Creates an array of language rules for ruby files.
Recognises continuous blocks of lines beginning with #
and =begin, =end multi-line comments.
Returns list of language rules.
optsObject processing options.
Options
multiObject multi-line rule configuration.singleObject single-line rule configuration.
sass
Creates an array of language rules for sass files.
Recognises terminated multi-line comments starting with /* and
continuous blocks of single-line comments beginning with //.
See the css language.
Returns list of language rules.
optsObject processing options.
scala
Creates an array of language rules for scala files.
Recognises continuous lines with // comments and terminated
multi-line comments starting with ``.
See the default settings.
Returns list of language rules.
optsObject processing options.
shell
Creates an array of language rules for shell files.
Recognises continuous blocks of lines beginning with #.
Returns list of language rules.
optsObject processing options.
Options
markRegExp sub pattern.trailRegExp pattern to strip trailing meta characters.
sql
Creates an array of language rules for SQL statements.
Recognises terminated multi-line comments started with /* and
continuous lines beginning with --.
If the mysql option is given continuous lines beginning with # are
also recognised.
Returns list of language rules.
optsObject processing options.
Options
includeBoolean mysql specific comment rule.
stylus
Creates an array of language rules for stylus files.
Recognises terminated multi-line comments starting with /* and
buffered multi-line blocks starting with /*! as well as
continuous blocks of single-line comments beginning with //.
See the css language.
Returns list of language rules.
optsObject processing options.
Options
singleObject|Boolean=true single-line comment options.multiObject|Boolean=true multi-line comment options.bufferObject|Boolean=true buffer comment options.
toml
Creates an array of language rules for TOML files.
Recognises continuous blocks of lines beginning with #.
See the shell language.
Returns list of language rules.
optsObject processing options.
typescript
Creates an array of language rules for typescript files.
Recognises continuous lines with // comments and terminated
multi-line comments starting with ``.
See the default settings.
Returns list of language rules.
optsObject processing options.
vim
Creates an array of language rules for vim files.
Recognises continuous blocks of lines beginning with ".
Returns list of language rules.
optsObject processing options.
Options
markRegExp sub pattern.trailRegExp pattern to strip trailing meta characters.
xml
Creates an array of language rules for XML files.
Recognises multi-line comments started with <!-- and terminated
with -->.
See the html language.
Returns list of language rules.
optsObject processing options.
yaml
Creates an array of language rules for YAML files.
Recognises continuous blocks of lines beginning with #.
See the shell language.
Returns list of language rules.
optsObject processing options.
Created by mkdoc on January 3, 2017