From 4eedaccffe4dd27f4e5c69a4f0d4662887dabaa2 Mon Sep 17 00:00:00 2001 From: vinhnghi223 Date: Tue, 16 Feb 2016 22:07:15 +0200 Subject: [PATCH] Prevented access index '1' of null --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 973cf50..31079af 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,8 @@ module.exports = function(input, options, cb) { // Find the title of the page by identifying the

// The second match is the inner group - var title = body.match('(.*)

')[1] || 'Page ' + (i + 1); + var foundHeadings = body.match('(.*)'); + var title = foundHeadings && foundHeadings[1] || 'Page ' + (i + 1); var anchor = title.toLowerCase().replace(/[^\w]+/g, '-'); return { title: title, anchor: anchor, body: body }