From 23435ce6b10b586aeff349d0aba37c8be23ab4c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20H=C3=A4usler?= Date: Sun, 22 Dec 2019 05:52:34 +0100 Subject: [PATCH] fix: 1733 wrong task list indentation in parser (#1835) --- src/muya/lib/parser/marked/lexer.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/muya/lib/parser/marked/lexer.js b/src/muya/lib/parser/marked/lexer.js index d7992687..31965b27 100644 --- a/src/muya/lib/parser/marked/lexer.js +++ b/src/muya/lib/parser/marked/lexer.js @@ -316,8 +316,8 @@ Lexer.prototype.token = function (src, top) { const itemWithBullet = cap[i] item = itemWithBullet let newIsTaskListItem = false - // Remove the list item's bullet - // so it is seen as the next token. + + // Remove the list item's bullet so it is seen as the next token. space = item.length let newBull item = item.replace(/^ *([*+-]|\d+(?:\.|\))) {0,4}/, function (m, p1) { @@ -327,13 +327,15 @@ Lexer.prototype.token = function (src, top) { }) const newIsOrdered = bull.length > 1 && /\d{1,9}/.test(newBull) - if (!newIsOrdered && this.options.gfm) { checked = this.rules.checkbox.exec(item) if (checked) { checked = checked[1] === 'x' || checked[1] === 'X' - item = item.replace(this.rules.checkbox, '') newIsTaskListItem = true + + // Remove the list item's checkbox and adjust indentation by removing checkbox length. + item = item.replace(this.rules.checkbox, '') + space -= 4 } else { checked = undefined } @@ -400,6 +402,7 @@ Lexer.prototype.token = function (src, top) { } else { prevItem = cap[i - 1] } + // Determine whether item is loose or not. If previous item is loose // this item is also loose. // A list is loose if any of its constituent list items are separated by blank lines, @@ -450,7 +453,6 @@ Lexer.prototype.token = function (src, top) { this.tokens.push({ type: 'list_end' }) - continue }