@@ -33,7 +33,7 @@ module.exports = toHTML;
3333const STABILITY_TEXT_REG_EXP = / ( .* : ) \s * ( \d ) ( [ \s \S ] * ) / ;
3434const DOC_CREATED_REG_EXP = / < ! - - \s * i n t r o d u c e d _ i n \s * = \s * v ( [ 0 - 9 ] + ) \. ( [ 0 - 9 ] + ) \. ( [ 0 - 9 ] + ) \s * - - > / ;
3535
36- // customized heading without id attribute
36+ // Customized heading without id attribute.
3737const renderer = new marked . Renderer ( ) ;
3838renderer . heading = function ( text , level ) {
3939 return `<h${ level } >${ text } </h${ level } >\n` ;
@@ -42,7 +42,7 @@ marked.setOptions({
4242 renderer : renderer
4343} ) ;
4444
45- // TODO(chrisdickinson): never stop vomitting / fix this.
45+ // TODO(chrisdickinson): never stop vomiting / fix this.
4646const gtocPath = path . resolve ( path . join (
4747 __dirname ,
4848 '..' ,
@@ -128,16 +128,16 @@ function render(opts, cb) {
128128 var { lexed, filename, template } = opts ;
129129 const nodeVersion = opts . nodeVersion || process . version ;
130130
131- // get the section
131+ // Get the section.
132132 const section = getSection ( lexed ) ;
133133
134134 filename = path . basename ( filename , '.md' ) ;
135135
136136 parseText ( lexed ) ;
137137 lexed = parseLists ( lexed ) ;
138138
139- // generate the table of contents.
140- // this mutates the lexed contents in-place.
139+ // Generate the table of contents.
140+ // This mutates the lexed contents in-place.
141141 buildToc ( lexed , filename , function ( er , toc ) {
142142 if ( er ) return cb ( er ) ;
143143
@@ -162,8 +162,8 @@ function render(opts, cb) {
162162
163163 template = template . replace ( / _ _ A L T D O C S _ _ / , altDocs ( filename ) ) ;
164164
165- // content has to be the last thing we do with
166- // the lexed tokens, because it's destructive.
165+ // Content has to be the last thing we do with the lexed tokens,
166+ // because it's destructive.
167167 const content = marked . parser ( lexed ) ;
168168 template = template . replace ( / _ _ C O N T E N T _ _ / g, content ) ;
169169
@@ -188,7 +188,7 @@ function analyticsScript(analytics) {
188188 ` ;
189189}
190190
191- // replace placeholders in text tokens
191+ // Replace placeholders in text tokens.
192192function replaceInText ( text ) {
193193 return linkJsTypeDocs ( linkManPages ( text ) ) ;
194194}
@@ -244,8 +244,8 @@ function altDocs(filename) {
244244 ` ;
245245}
246246
247- // handle general body-text replacements
248- // for example, link man page references to the actual page
247+ // Handle general body-text replacements.
248+ // For example, link man page references to the actual page.
249249function parseText ( lexed ) {
250250 lexed . forEach ( function ( tok ) {
251251 if ( tok . type === 'table' ) {
@@ -272,8 +272,8 @@ function parseText(lexed) {
272272 } ) ;
273273}
274274
275- // just update the list item text in-place.
276- // lists that come right after a heading are what we're after.
275+ // Just update the list item text in-place.
276+ // Lists that come right after a heading are what we're after.
277277function parseLists ( input ) {
278278 var state = null ;
279279 const savedState = [ ] ;
@@ -299,8 +299,8 @@ function parseLists(input) {
299299 const stabilityMatch = tok . text . match ( STABILITY_TEXT_REG_EXP ) ;
300300 const stability = Number ( stabilityMatch [ 2 ] ) ;
301301 const isStabilityIndex =
302- index - 2 === headingIndex || // general
303- index - 3 === headingIndex ; // with api_metadata block
302+ index - 2 === headingIndex || // General.
303+ index - 3 === headingIndex ; // With api_metadata block.
304304
305305 if ( heading && isStabilityIndex ) {
306306 heading . stability = stability ;
@@ -408,17 +408,17 @@ function parseYAML(text) {
408408 return html . join ( '\n' ) ;
409409}
410410
411- // Syscalls which appear in the docs, but which only exist in BSD / OSX
411+ // Syscalls which appear in the docs, but which only exist in BSD / macOS.
412412const BSD_ONLY_SYSCALLS = new Set ( [ 'lchmod' ] ) ;
413413
414- // Handle references to man pages, eg "open(2)" or "lchmod(2)"
415- // Returns modified text, with such refs replace with HTML links, for example
416- // '<a href="http://man7.org/linux/man-pages/man2/open.2.html">open(2)</a>'
414+ // Handle references to man pages, eg "open(2)" or "lchmod(2)".
415+ // Returns modified text, with such refs replaced with HTML links, for example
416+ // '<a href="http://man7.org/linux/man-pages/man2/open.2.html">open(2)</a>'.
417417function linkManPages ( text ) {
418418 return text . replace (
419419 / ( ^ | \s ) ( [ a - z . ] + ) \( ( \d ) ( [ a - z ] ? ) \) / gm,
420420 ( match , beginning , name , number , optionalCharacter ) => {
421- // name consists of lowercase letters, number is a single digit
421+ // Name consists of lowercase letters, number is a single digit.
422422 const displayAs = `${ name } (${ number } ${ optionalCharacter } )` ;
423423 if ( BSD_ONLY_SYSCALLS . has ( name ) ) {
424424 return `${ beginning } <a href="https://www.freebsd.org/cgi/man.cgi?query=${ name } ` +
@@ -436,7 +436,7 @@ function linkJsTypeDocs(text) {
436436 var typeMatches ;
437437
438438 // Handle types, for example the source Markdown might say
439- // "This argument should be a {Number} or {String}"
439+ // "This argument should be a {Number} or {String}".
440440 for ( i = 0 ; i < parts . length ; i += 2 ) {
441441 typeMatches = parts [ i ] . match ( / \{ ( [ ^ } ] + ) \} / g) ;
442442 if ( typeMatches ) {
@@ -446,7 +446,7 @@ function linkJsTypeDocs(text) {
446446 }
447447 }
448448
449- //XXX maybe put more stuff here?
449+ // TODO: maybe put more stuff here?
450450 return parts . join ( '`' ) ;
451451}
452452
@@ -461,7 +461,7 @@ function parseAPIHeader(text) {
461461 return text ;
462462}
463463
464- // section is just the first heading
464+ // Section is just the first heading.
465465function getSection ( lexed ) {
466466 for ( var i = 0 , l = lexed . length ; i < l ; i ++ ) {
467467 var tok = lexed [ i ] ;
@@ -533,7 +533,7 @@ const numberRe = /^(\d*)/;
533533function versionSort ( a , b ) {
534534 a = a . trim ( ) ;
535535 b = b . trim ( ) ;
536- let i = 0 ; // common prefix length
536+ let i = 0 ; // Common prefix length.
537537 while ( i < a . length && i < b . length && a [ i ] === b [ i ] ) i ++ ;
538538 a = a . substr ( i ) ;
539539 b = b . substr ( i ) ;
0 commit comments