2014-01-14 00:01:17 +01:00
|
|
|
args = Array.prototype.slice.call(args,1);
|
2014-01-04 17:57:43 +01:00
|
|
|
|
2014-01-12 12:26:26 +01:00
|
|
|
// wph 20140105 trim not availabe in String on Mac OS.
|
|
|
|
if (typeof String.prototype.trim == 'undefined'){
|
|
|
|
String.prototype.trim = function(){
|
|
|
|
return this.replace(/^\s+|\s+$/g,'');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-01-04 17:57:43 +01:00
|
|
|
var template = args[0];
|
|
|
|
|
|
|
|
var BufferedReader = java.io.BufferedReader;
|
|
|
|
var FileReader = java.io.FileReader;
|
|
|
|
|
|
|
|
var contents = [], line = undefined;
|
|
|
|
var br = new BufferedReader( new FileReader(template) );
|
|
|
|
|
|
|
|
while ( (line = br.readLine()) != null){
|
|
|
|
contents.push(line);
|
|
|
|
}
|
|
|
|
br.close();
|
|
|
|
|
2014-01-06 21:54:53 +01:00
|
|
|
var anchors = {};
|
|
|
|
|
2014-01-04 21:23:17 +01:00
|
|
|
var createLink = function(text){
|
|
|
|
var result = text.replace(/_/g,'_');
|
|
|
|
result = result.replace(/[^a-zA-Z0-9 _\-]/g,'');
|
|
|
|
result = result.replace(/ /g,'-');
|
2014-01-06 21:54:53 +01:00
|
|
|
var result = result.toLowerCase();
|
|
|
|
if (anchors[result]){
|
|
|
|
result = result + '-' + (anchors[result]++);
|
|
|
|
}
|
|
|
|
anchors[result] = 1;
|
|
|
|
return result;
|
2014-01-04 21:23:17 +01:00
|
|
|
};
|
2014-01-14 00:01:17 +01:00
|
|
|
java.lang.System.out.println('## Table of Contents');
|
2014-01-04 17:57:43 +01:00
|
|
|
|
|
|
|
for (var i = 0; i < contents.length; i++){
|
|
|
|
line = contents[i];
|
|
|
|
if (line.match(/^##\s+/)){
|
|
|
|
var h2 = line.match(/^##\s+(.*)/)[1].trim();
|
2014-01-04 21:23:17 +01:00
|
|
|
var link = createLink(h2);
|
2014-01-14 00:01:17 +01:00
|
|
|
java.lang.System.out.println (' * [' + h2 + '](#' + link + ')');
|
2014-01-04 17:57:43 +01:00
|
|
|
}
|
|
|
|
if (line.match(/^###\s+/)){
|
|
|
|
var h3 = line.match(/^###\s+(.*)/)[1].trim();
|
2014-01-04 21:23:17 +01:00
|
|
|
var link = createLink(h3);
|
2014-01-14 00:01:17 +01:00
|
|
|
java.lang.System.out.println (' * [' + h3 + '](#' + link + ')');
|
2014-01-04 17:57:43 +01:00
|
|
|
}
|
|
|
|
}
|