Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing bug about outputting "undefined" bullets #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down