From 2ef8825a7fc3479120e5031789acc3b4424902f5 Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Thu, 23 Oct 2014 11:27:59 +0400 Subject: [PATCH] Moved tight paragraphs marking to separate fn --- lib/rules_block/list.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/rules_block/list.js b/lib/rules_block/list.js index 2101868..7b157ae 100644 --- a/lib/rules_block/list.js +++ b/lib/rules_block/list.js @@ -68,6 +68,19 @@ function skipOrderedListMarker(state, startLine) { return pos; } +function markTightParagraphs(state, idx) { + var i, l, + level = state.level + 2; + + for (i = idx + 2, l = state.tokens.length - 2; i < l; i++) { + if (state.tokens[i].level === level && state.tokens[i].type === 'paragraph_open') { + state.tokens[i + 2].tight = true; + state.tokens[i].tight = true; + i += 2; + } + } +} + module.exports = function list(state, startLine, endLine, silent) { var nextLine, @@ -90,7 +103,7 @@ module.exports = function list(state, startLine, endLine, silent) { itemLines, tight = true, terminatorRules = state.parser._rulesListTerm, - i, l, terminate, level, tokens; + i, l, terminate; // Detect list type and position after marker if ((posAfterMarker = skipOrderedListMarker(state, startLine)) >= 0) { @@ -247,16 +260,7 @@ module.exports = function list(state, startLine, endLine, silent) { // mark paragraphs tight if needed if (tight) { - level = state.level + 2; - tokens = state.tokens; - - for (i = listTokIdx + 2, l = tokens.length - 2; i < l; i++) { - if (tokens[i].level === level && tokens[i].type === 'paragraph_open') { - tokens[i].tight = true; - i += 2; - tokens[i].tight = true; - } - } + markTightParagraphs(state, listTokIdx); } return true;