Skip to content

Commit

Permalink
Easy filtering of code blocks from hashed headers
Browse files Browse the repository at this point in the history
  • Loading branch information
miangraham-ss committed Feb 25, 2013
1 parent 4ebc4f5 commit cc92b73
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ function addAnchor(header) {


function getHashedHeaders (_lines) {
var inCodeBlock = false;

// Turn all headers into '## xxx' even if they were '## xxx ##'
function normalize(header) {
return header.replace(/[ #]+$/, '');
}

// Find headers of the form '### xxxx xxx xx [###]'
return _lines
.filter(function (x) {
if (x.match(/^```/)) {
inCodeBlock = !inCodeBlock;
}
return !inCodeBlock;
})
.map(function (x, index) {
var match = /^(\#{1,8})[ ]*(.+)$/.exec(x);

Expand Down

0 comments on commit cc92b73

Please sign in to comment.