From 0b81c1105e90eaaac0ceac016dd5683d7f61d9a4 Mon Sep 17 00:00:00 2001 From: Alessandro Venturini Date: Fri, 22 Sep 2023 11:50:08 +0200 Subject: [PATCH] Fixing bug about outputting "undefined" bullets --- index.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 64a5eb1..69839a5 100644 --- a/index.js +++ b/index.js @@ -103,11 +103,16 @@ function generate(options) { } } + // Searching for the first H1 and removing it if set by the options + let firstH1Index = result.findIndex(e => e.lvl === 1); + if (stripFirst && firstH1Index >= 0) { + result.splice(firstH1Index, 1); + } + opts.highest = highest(result); res.highest = opts.highest; res.tokens = tokens; - if (stripFirst) result = result.slice(1); res.content = bullets(result, opts); res.content += (opts.append || ''); return res; @@ -126,25 +131,18 @@ function generate(options) { function bullets(arr, options) { var opts = utils.merge({indent: ' '}, options); opts.chars = opts.chars || opts.bullets || ['-', '*', '+']; - var unindent = 0; var listitem = utils.li(opts); var fn = typeof opts.filter === 'function' ? opts.filter : null; - // Keep the first h1? This is `true` by default - if (opts && opts.firsth1 === false) { - unindent = 1; - } - var len = arr.length; var res = []; var i = 0; while (i < len) { var ele = arr[i++]; - ele.lvl -= unindent; if (fn && !fn(ele.content, ele, arr)) { continue; }