diff --git a/markdown-it-attrs.browser.js b/markdown-it-attrs.browser.js index 794234c..c065eba 100644 --- a/markdown-it-attrs.browser.js +++ b/markdown-it-attrs.browser.js @@ -175,15 +175,27 @@ function firstTokenNotHidden(tokens, i) { } /** - * Find first bullet list open. + * Find corresponding bullet/ordered list open. */ function bulletListOpen(tokens, i) { - if (tokens[i] && - tokens[i].type !== 'bullet_list_open' && - tokens[i].type !== 'ordered_list_open') { - return bulletListOpen(tokens, i - 1); + var level = 0; + var token; + for (; i >= 0; i -= 1) { + token = tokens[i]; + // jump past nested lists, level == 0 and open -> correct opening token + if (token.type === 'bullet_list_close' || + token.type === 'ordered_list_close') { + level += 1; + } + if (token.type === 'bullet_list_open' || + token.type === 'ordered_list_open') { + if (level === 0) { + return token; + } else { + level -= 1; + } + } } - return tokens[i]; } /** diff --git a/package.json b/package.json index a8a5011..9e25001 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "markdown-it-attrs", - "version": "0.7.4", + "version": "0.8.0", "description": "Add classes, identifiers and attributes to your markdown with {} curly brackets, similar to pandoc's header attributes", "main": "index.js", "license": "MIT",