code-part
Parts comments and code into a data structure with htmlParser2 for html and docco for everything else. Also tracks starting line number for each chunk so it's possible to add line number if you plan to use a syntax highlighter like google-code-prettify to display the code.
Usage
var part = ; // Path is used to decide which parser // to use for both code-part and docco. var sections = ; // config is passed to docco // not used in htmlParser2 code path // If code is null, path is read in as code
Sections
- input:
// comment 1var code = 1;// comment 2if code code += 1
- output:
docsText: 'comment 1\n' codeText: 'var code = 1;\n' docsLine: 1 codeLine: 2 docsText: 'comment 2\n' codeText: 'if (code) code += 1\n\n' docsLine: 3 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: 2 docsText: 'main body' docsLine: 5 codeText: '\n <h1>hello world</h1>\n' codeLine: 5 docsText: 'the end' docsLine: 7 codeText: '\n</body>\n</html>\n' codeLine: 7