Skip to content

Commit

Permalink
extracting headers
Browse files Browse the repository at this point in the history
  • Loading branch information
thlorenz committed May 27, 2012
1 parent 421f919 commit 285f6d2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ results
node_modules
npm-debug.log
samples
tmp_samples
26 changes: 21 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var path = require('path'),
file = require('./lib/file');

// TODO: from commandline
var dir = 'samples';
var dir = 'tmp_samples';

function isAbsolute(path) {
if ('/' == path[0]) return true;
Expand All @@ -30,13 +30,29 @@ function transformAndSave(files, fcb) {
}

function transform (f, content, cb) {
console.log('transforming', f);
console.log(content);
console.log('transforming', f.name);
var lines = content.split('\n');
var hashedLines = _(lines)
.chain()
.map(function (x) {
var match = /^(\#{1,8}) *(.+)$/.exec(x);
if (match) {
return {
rank : match[1].length,
title : match[2]
};
} else {
return null;
}
})
.filter(function (x) { return x !== null; })
.value();

console.log(hashedLines);

cb();
}



file.findMarkdownFiles(target, function (files) {
transformAndSave(files, function () { console.log('Everything is OK'); });
});
Expand Down

0 comments on commit 285f6d2

Please sign in to comment.