code-part
Parts comments and code into a data structure with htmlParser2 for html and line based comment parsing for everything else. code-part tracks starting line numbers for each code section so it's possible to add line numbers if you plan to use a syntax highlighter like google-code-prettify to display your code.
code-part's code for line based parsing was modified from docco. This code base does not include docco. The only current dependencies are htmlParser2 and lodash.
Comment support for everything except html only extracts comments
at the beginning of the line and only the single line version of
the languages comment. For example /* not extracted */
does not
get extracted but // extracted
does.
To see a list of the languages supported by the line based parsing have a look at resources/languages.json.
Usage
var part = ; // Path is used to decide which parser to use // (html or lineBased currently) and decides comment // parsing in lineBased. var sections = ; // If code is null, the specified path is assumed // to be a path on the file system and is read in // with `readFileSync`.
Configuration
var section = ;
Output
- input:
// comment 1var code = 1;// comment 2if code code += 1
- output:
docsText: 'comment 1\n' docsLine: 1 codeText: 'var code = 1;\n' codeLine: 2 docsText: 'comment 2\n' docsLine: 3 codeText: 'if (code) code += 1\n' codeLine: 4
- input:
<!-- title part --> title <!-- main body --> hello world<!-- the end -->
output:
docsText: '' docsLine: 1 codeText: '<html>\n ' codeLine: 1 docsText: 'title part' docsLine: 2 codeText: '\n <head><title> title </title></head>\n<body>\n ' codeLine: 3 docsText: 'main body' docsLine: 5 codeText: '\n <h1>hello world</h1>\n' codeLine: 6 docsText: 'the end' docsLine: 7 codeText: '\n</body>\n</html>\n' codeLine: 8
BUGS
It is possible to use jade, but multi-line comments are not supported.
Supported:
html // comment 1 head // comment 2 title A Title
Not Supported:
html
//
This is a
multi-line comment
and is not supported
head
title Another Title
TODO
- Multi-line comment parsing like jade comments.
LICENSE
Copyright (C) 2014 Scott Beck, all rights reserved
Licensed under the MIT license