Skip to content
Myr

toc.js

This file

Path

support/toc.js

21 lines · 706 bytes · JavaScript

Last changed by

More docsTj Holowaychukbefore adoptionde81ee7

History of this file

Take it

Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f

lines 1–13why, one step back
1#!/usr/bin/env node
23var fs = require('fs'),4 file = process.argv[2];56if (file) {7 var js = fs.readFileSync(file, 'utf8'),8 headers = js.match(/<h3 id="(.*?)">(.*?)<\/h3>/g),9 toc = ['<ul id="toc">'];10 if (js.indexOf('id="toc"') < 0) {11 headers.forEach(function(header){12 var captures = header.match(/id="(.*?)">(.*?)</),13 id = captures[1],

More docsTj Holowaychukbefore adoptionde81ee7

line 14why, one step back
14 title = captures[2].replace(/\(.*?\)/, '()');

Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f

lines 15–21why, one step back
15 toc.push('<li><a href="#' + id + '">' + title + '</a></li>');
16 });17 toc.push('</ul>');18 js = js.replace('<div id="container">', '<div id="container">' + toc.join('\n'));19 fs.writeFileSync(file, js);20 }21}