Skip to content

Commit

Permalink
Merge pull request #1 from vinhnghi223/feature/prevent-null-error
Browse files Browse the repository at this point in the history
Avoid accessing index '1' of null
  • Loading branch information
gakimball committed Feb 16, 2016
2 parents 08737f8 + 4eedacc commit 488124e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module.exports = function(input, options, cb) {

// Find the title of the page by identifying the <h1>
// The second match is the inner group
var title = body.match('<h1.*>(.*)</h1>')[1] || 'Page ' + (i + 1);
var foundHeadings = body.match('<h1.*>(.*)</h1>');
var title = foundHeadings && foundHeadings[1] || 'Page ' + (i + 1);
var anchor = title.toLowerCase().replace(/[^\w]+/g, '-');

return { title: title, anchor: anchor, body: body }
Expand Down

0 comments on commit 488124e

Please sign in to comment.