diff --git a/packages/remark-parse/lib/tokenize/list.js b/packages/remark-parse/lib/tokenize/list.js index 9164c8167..2d5b227c0 100644 --- a/packages/remark-parse/lib/tokenize/list.js +++ b/packages/remark-parse/lib/tokenize/list.js @@ -426,13 +426,15 @@ function normalListItem(ctx, value, position) { var trimmedLines; var index; var length; + var maxIndent; /* Remove the list-item’s bullet. */ value = value.replace(EXPRESSION_BULLET, replacer); lines = value.split(C_NEWLINE); - trimmedLines = removeIndent(value, getIndent(max).indent).split(C_NEWLINE); + maxIndent = getIndent(max); + trimmedLines = removeIndent(value, maxIndent.indent).split(C_NEWLINE); /* We replaced the initial bullet with something * else above, which was used to trick @@ -467,7 +469,7 @@ function normalListItem(ctx, value, position) { $2 = C_SPACE + $2; } - max = $1 + repeat(C_SPACE, $2.length) + $3; + max = $1 + repeat(C_SPACE, Math.max($2.length, TAB_SIZE)) + $3; return max + rest; } diff --git a/packages/remark-parse/lib/util/remove-indentation.js b/packages/remark-parse/lib/util/remove-indentation.js index 20f18be74..b9ac25f9f 100644 --- a/packages/remark-parse/lib/util/remove-indentation.js +++ b/packages/remark-parse/lib/util/remove-indentation.js @@ -8,7 +8,6 @@ module.exports = indentation; var C_SPACE = ' '; var C_NEWLINE = '\n'; -var C_TAB = '\t'; /* Remove the minimum indent from every line in `value`. * Supports both tab, spaced, and mixed indentation (as @@ -21,7 +20,6 @@ function indentation(value, maximum) { var index; var indentation; var stops; - var padding; values.unshift(repeat(C_SPACE, maximum) + '!'); @@ -56,17 +54,7 @@ function indentation(value, maximum) { index--; } - if ( - trim(values[position]).length !== 0 && - minIndent && - index !== minIndent - ) { - padding = C_TAB; - } else { - padding = ''; - } - - values[position] = padding + values[position].slice( + values[position] = values[position].slice( index in stops ? stops[index] + 1 : 0 ); } diff --git a/test/fixtures/tree/list-indentation.nooutput.commonmark.json b/test/fixtures/tree/list-indentation.nooutput.commonmark.json index 7efac8063..ad49bbae8 100644 --- a/test/fixtures/tree/list-indentation.nooutput.commonmark.json +++ b/test/fixtures/tree/list-indentation.nooutput.commonmark.json @@ -853,12 +853,12 @@ "children": [ { "type": "text", - "value": " World 5a.", + "value": "World 5a.", "position": { "start": { "line": 35, - "column": 3, - "offset": 238 + "column": 6, + "offset": 241 }, "end": { "line": 35, @@ -872,8 +872,8 @@ "position": { "start": { "line": 35, - "column": 3, - "offset": 238 + "column": 6, + "offset": 241 }, "end": { "line": 35, @@ -910,22 +910,54 @@ { "type": "code", "lang": null, - "value": "Hello 5b\n\nWorld 5b.", + "value": "Hello 5b", "position": { "start": { "line": 37, "column": 3, "offset": 254 }, + "end": { + "line": 37, + "column": 15, + "offset": 266 + }, + "indent": [] + } + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": " World 5b.", + "position": { + "start": { + "line": 39, + "column": 6, + "offset": 273 + }, + "end": { + "line": 39, + "column": 16, + "offset": 283 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 39, + "column": 6, + "offset": 273 + }, "end": { "line": 39, "column": 16, "offset": 283 }, - "indent": [ - 1, - 3 - ] + "indent": [] } } ], diff --git a/test/fixtures/tree/list-indentation.nooutput.json b/test/fixtures/tree/list-indentation.nooutput.json index 617f68055..b70dafb6d 100644 --- a/test/fixtures/tree/list-indentation.nooutput.json +++ b/test/fixtures/tree/list-indentation.nooutput.json @@ -787,12 +787,12 @@ "children": [ { "type": "text", - "value": " World 5a.", + "value": "World 5a.", "position": { "start": { "line": 35, - "column": 3, - "offset": 238 + "column": 6, + "offset": 241 }, "end": { "line": 35, @@ -806,8 +806,8 @@ "position": { "start": { "line": 35, - "column": 3, - "offset": 238 + "column": 6, + "offset": 241 }, "end": { "line": 35, @@ -844,22 +844,54 @@ { "type": "code", "lang": null, - "value": "Hello 5b\n\nWorld 5b.", + "value": "Hello 5b", "position": { "start": { "line": 37, "column": 3, "offset": 254 }, + "end": { + "line": 37, + "column": 15, + "offset": 266 + }, + "indent": [] + } + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": " World 5b.", + "position": { + "start": { + "line": 39, + "column": 6, + "offset": 273 + }, + "end": { + "line": 39, + "column": 16, + "offset": 283 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 39, + "column": 6, + "offset": 273 + }, "end": { "line": 39, "column": 16, "offset": 283 }, - "indent": [ - 1, - 3 - ] + "indent": [] } } ], diff --git a/test/fixtures/tree/list-indentation.nooutput.nogfm.commonmark.json b/test/fixtures/tree/list-indentation.nooutput.nogfm.commonmark.json index 7efac8063..ad49bbae8 100644 --- a/test/fixtures/tree/list-indentation.nooutput.nogfm.commonmark.json +++ b/test/fixtures/tree/list-indentation.nooutput.nogfm.commonmark.json @@ -853,12 +853,12 @@ "children": [ { "type": "text", - "value": " World 5a.", + "value": "World 5a.", "position": { "start": { "line": 35, - "column": 3, - "offset": 238 + "column": 6, + "offset": 241 }, "end": { "line": 35, @@ -872,8 +872,8 @@ "position": { "start": { "line": 35, - "column": 3, - "offset": 238 + "column": 6, + "offset": 241 }, "end": { "line": 35, @@ -910,22 +910,54 @@ { "type": "code", "lang": null, - "value": "Hello 5b\n\nWorld 5b.", + "value": "Hello 5b", "position": { "start": { "line": 37, "column": 3, "offset": 254 }, + "end": { + "line": 37, + "column": 15, + "offset": 266 + }, + "indent": [] + } + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": " World 5b.", + "position": { + "start": { + "line": 39, + "column": 6, + "offset": 273 + }, + "end": { + "line": 39, + "column": 16, + "offset": 283 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 39, + "column": 6, + "offset": 273 + }, "end": { "line": 39, "column": 16, "offset": 283 }, - "indent": [ - 1, - 3 - ] + "indent": [] } } ], diff --git a/test/fixtures/tree/list-indentation.nooutput.nogfm.json b/test/fixtures/tree/list-indentation.nooutput.nogfm.json index 617f68055..b70dafb6d 100644 --- a/test/fixtures/tree/list-indentation.nooutput.nogfm.json +++ b/test/fixtures/tree/list-indentation.nooutput.nogfm.json @@ -787,12 +787,12 @@ "children": [ { "type": "text", - "value": " World 5a.", + "value": "World 5a.", "position": { "start": { "line": 35, - "column": 3, - "offset": 238 + "column": 6, + "offset": 241 }, "end": { "line": 35, @@ -806,8 +806,8 @@ "position": { "start": { "line": 35, - "column": 3, - "offset": 238 + "column": 6, + "offset": 241 }, "end": { "line": 35, @@ -844,22 +844,54 @@ { "type": "code", "lang": null, - "value": "Hello 5b\n\nWorld 5b.", + "value": "Hello 5b", "position": { "start": { "line": 37, "column": 3, "offset": 254 }, + "end": { + "line": 37, + "column": 15, + "offset": 266 + }, + "indent": [] + } + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": " World 5b.", + "position": { + "start": { + "line": 39, + "column": 6, + "offset": 273 + }, + "end": { + "line": 39, + "column": 16, + "offset": 283 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 39, + "column": 6, + "offset": 273 + }, "end": { "line": 39, "column": 16, "offset": 283 }, - "indent": [ - 1, - 3 - ] + "indent": [] } } ], diff --git a/test/fixtures/tree/list-item-newline.nooutput.json b/test/fixtures/tree/list-item-newline.nooutput.json index 236f2ec7b..5caa1e5ed 100644 --- a/test/fixtures/tree/list-item-newline.nooutput.json +++ b/test/fixtures/tree/list-item-newline.nooutput.json @@ -72,12 +72,12 @@ "children": [ { "type": "text", - "value": " Bar", + "value": "Bar", "position": { "start": { "line": 3, - "column": 2, - "offset": 11 + "column": 5, + "offset": 14 }, "end": { "line": 3, @@ -91,8 +91,8 @@ "position": { "start": { "line": 3, - "column": 2, - "offset": 11 + "column": 5, + "offset": 14 }, "end": { "line": 3, diff --git a/test/fixtures/tree/lists-with-code-and-rules.json b/test/fixtures/tree/lists-with-code-and-rules.json index 10d015793..67225c675 100644 --- a/test/fixtures/tree/lists-with-code-and-rules.json +++ b/test/fixtures/tree/lists-with-code-and-rules.json @@ -228,8 +228,8 @@ "position": { "start": { "line": 7, - "column": 11, - "offset": 53 + "column": 13, + "offset": 55 }, "end": { "line": 7, @@ -283,8 +283,8 @@ "position": { "start": { "line": 8, - "column": 11, - "offset": 73 + "column": 13, + "offset": 75 }, "end": { "line": 8, @@ -338,8 +338,8 @@ "position": { "start": { "line": 9, - "column": 11, - "offset": 92 + "column": 13, + "offset": 94 }, "end": { "line": 9, @@ -353,8 +353,8 @@ "position": { "start": { "line": 7, - "column": 11, - "offset": 53 + "column": 13, + "offset": 55 }, "end": { "line": 9, @@ -362,8 +362,8 @@ "offset": 100 }, "indent": [ - 11, - 11 + 13, + 13 ] } } @@ -371,8 +371,8 @@ "position": { "start": { "line": 6, - "column": 7, - "offset": 35 + "column": 9, + "offset": 37 }, "end": { "line": 9, @@ -380,9 +380,9 @@ "offset": 100 }, "indent": [ - 7, - 7, - 7 + 9, + 9, + 9 ] } } @@ -390,8 +390,8 @@ "position": { "start": { "line": 6, - "column": 7, - "offset": 35 + "column": 9, + "offset": 37 }, "end": { "line": 9, @@ -399,9 +399,9 @@ "offset": 100 }, "indent": [ - 7, - 7, - 7 + 9, + 9, + 9 ] } } @@ -1059,24 +1059,89 @@ } }, { - "type": "code", - "lang": null, - "value": "foo\n---\nbar", + "type": "paragraph", + "children": [ + { + "type": "text", + "value": " foo", + "position": { + "start": { + "line": 49, + "column": 10, + "offset": 503 + }, + "end": { + "line": 49, + "column": 16, + "offset": 509 + }, + "indent": [] + } + } + ], "position": { "start": { "line": 49, - "column": 9, - "offset": 502 + "column": 10, + "offset": 503 + }, + "end": { + "line": 49, + "column": 16, + "offset": 509 + }, + "indent": [] + } + }, + { + "type": "thematicBreak", + "position": { + "start": { + "line": 50, + "column": 10, + "offset": 519 + }, + "end": { + "line": 50, + "column": 16, + "offset": 525 + }, + "indent": [] + } + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": " bar", + "position": { + "start": { + "line": 51, + "column": 10, + "offset": 535 + }, + "end": { + "line": 51, + "column": 16, + "offset": 541 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 51, + "column": 10, + "offset": 535 }, "end": { "line": 51, "column": 16, "offset": 541 }, - "indent": [ - 9, - 9 - ] + "indent": [] } } ], diff --git a/test/fixtures/tree/lists-with-code-and-rules.nogfm.json b/test/fixtures/tree/lists-with-code-and-rules.nogfm.json index 4a95251f8..3ac430aed 100644 --- a/test/fixtures/tree/lists-with-code-and-rules.nogfm.json +++ b/test/fixtures/tree/lists-with-code-and-rules.nogfm.json @@ -228,8 +228,8 @@ "position": { "start": { "line": 7, - "column": 11, - "offset": 53 + "column": 13, + "offset": 55 }, "end": { "line": 7, @@ -283,8 +283,8 @@ "position": { "start": { "line": 8, - "column": 11, - "offset": 73 + "column": 13, + "offset": 75 }, "end": { "line": 8, @@ -338,8 +338,8 @@ "position": { "start": { "line": 9, - "column": 11, - "offset": 92 + "column": 13, + "offset": 94 }, "end": { "line": 9, @@ -353,8 +353,8 @@ "position": { "start": { "line": 7, - "column": 11, - "offset": 53 + "column": 13, + "offset": 55 }, "end": { "line": 9, @@ -362,8 +362,8 @@ "offset": 100 }, "indent": [ - 11, - 11 + 13, + 13 ] } } @@ -371,8 +371,8 @@ "position": { "start": { "line": 6, - "column": 7, - "offset": 35 + "column": 9, + "offset": 37 }, "end": { "line": 9, @@ -380,9 +380,9 @@ "offset": 100 }, "indent": [ - 7, - 7, - 7 + 9, + 9, + 9 ] } } @@ -390,8 +390,8 @@ "position": { "start": { "line": 6, - "column": 7, - "offset": 35 + "column": 9, + "offset": 37 }, "end": { "line": 9, @@ -399,9 +399,9 @@ "offset": 100 }, "indent": [ - 7, - 7, - 7 + 9, + 9, + 9 ] } } @@ -1453,24 +1453,89 @@ } }, { - "type": "code", - "lang": null, - "value": "foo\n---\nbar", + "type": "paragraph", + "children": [ + { + "type": "text", + "value": " foo", + "position": { + "start": { + "line": 49, + "column": 10, + "offset": 503 + }, + "end": { + "line": 49, + "column": 16, + "offset": 509 + }, + "indent": [] + } + } + ], "position": { "start": { "line": 49, - "column": 9, - "offset": 502 + "column": 10, + "offset": 503 + }, + "end": { + "line": 49, + "column": 16, + "offset": 509 + }, + "indent": [] + } + }, + { + "type": "thematicBreak", + "position": { + "start": { + "line": 50, + "column": 10, + "offset": 519 + }, + "end": { + "line": 50, + "column": 16, + "offset": 525 + }, + "indent": [] + } + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": " bar", + "position": { + "start": { + "line": 51, + "column": 10, + "offset": 535 + }, + "end": { + "line": 51, + "column": 16, + "offset": 541 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 51, + "column": 10, + "offset": 535 }, "end": { "line": 51, "column": 16, "offset": 541 }, - "indent": [ - 9, - 9 - ] + "indent": [] } } ], diff --git a/test/fixtures/tree/mixed-indentation.commonmark.json b/test/fixtures/tree/mixed-indentation.commonmark.json index 153fa5c73..def435448 100644 --- a/test/fixtures/tree/mixed-indentation.commonmark.json +++ b/test/fixtures/tree/mixed-indentation.commonmark.json @@ -53,7 +53,7 @@ "children": [ { "type": "text", - "value": "Very long\n\t\t\tparagraph", + "value": "Very long\n\tparagraph", "position": { "start": { "line": 3, @@ -66,7 +66,7 @@ "offset": 48 }, "indent": [ - 0 + 2 ] } } @@ -83,7 +83,7 @@ "offset": 48 }, "indent": [ - 0 + 2 ] } } @@ -221,7 +221,7 @@ "children": [ { "type": "text", - "value": "Very long\n\tparagraph", + "value": "Very long\nparagraph", "position": { "start": { "line": 9, @@ -234,7 +234,7 @@ "offset": 99 }, "indent": [ - 2 + 3 ] } } @@ -251,7 +251,7 @@ "offset": 99 }, "indent": [ - 2 + 3 ] } } @@ -305,7 +305,7 @@ "children": [ { "type": "text", - "value": "Very long\n\tparagraph", + "value": "Very long\nparagraph", "position": { "start": { "line": 12, @@ -318,7 +318,7 @@ "offset": 125 }, "indent": [ - 2 + 3 ] } } @@ -335,7 +335,7 @@ "offset": 125 }, "indent": [ - 2 + 3 ] } } diff --git a/test/fixtures/tree/mixed-indentation.json b/test/fixtures/tree/mixed-indentation.json index 153fa5c73..def435448 100644 --- a/test/fixtures/tree/mixed-indentation.json +++ b/test/fixtures/tree/mixed-indentation.json @@ -53,7 +53,7 @@ "children": [ { "type": "text", - "value": "Very long\n\t\t\tparagraph", + "value": "Very long\n\tparagraph", "position": { "start": { "line": 3, @@ -66,7 +66,7 @@ "offset": 48 }, "indent": [ - 0 + 2 ] } } @@ -83,7 +83,7 @@ "offset": 48 }, "indent": [ - 0 + 2 ] } } @@ -221,7 +221,7 @@ "children": [ { "type": "text", - "value": "Very long\n\tparagraph", + "value": "Very long\nparagraph", "position": { "start": { "line": 9, @@ -234,7 +234,7 @@ "offset": 99 }, "indent": [ - 2 + 3 ] } } @@ -251,7 +251,7 @@ "offset": 99 }, "indent": [ - 2 + 3 ] } } @@ -305,7 +305,7 @@ "children": [ { "type": "text", - "value": "Very long\n\tparagraph", + "value": "Very long\nparagraph", "position": { "start": { "line": 12, @@ -318,7 +318,7 @@ "offset": 125 }, "indent": [ - 2 + 3 ] } } @@ -335,7 +335,7 @@ "offset": 125 }, "indent": [ - 2 + 3 ] } } diff --git a/test/fixtures/tree/task-list-unordered-asterisk.json b/test/fixtures/tree/task-list-unordered-asterisk.json index 3a20ea406..2ecc9a537 100644 --- a/test/fixtures/tree/task-list-unordered-asterisk.json +++ b/test/fixtures/tree/task-list-unordered-asterisk.json @@ -207,8 +207,8 @@ "position": { "start": { "line": 4, - "column": 3, - "offset": 63 + "column": 5, + "offset": 65 }, "end": { "line": 4, @@ -222,8 +222,8 @@ "position": { "start": { "line": 4, - "column": 3, - "offset": 63 + "column": 5, + "offset": 65 }, "end": { "line": 4, diff --git a/test/fixtures/tree/task-list-unordered-asterisk.nogfm.json b/test/fixtures/tree/task-list-unordered-asterisk.nogfm.json index 78212d025..2859b0111 100644 --- a/test/fixtures/tree/task-list-unordered-asterisk.nogfm.json +++ b/test/fixtures/tree/task-list-unordered-asterisk.nogfm.json @@ -318,8 +318,8 @@ "position": { "start": { "line": 4, - "column": 3, - "offset": 63 + "column": 5, + "offset": 65 }, "end": { "line": 4, @@ -333,8 +333,8 @@ "position": { "start": { "line": 4, - "column": 3, - "offset": 63 + "column": 5, + "offset": 65 }, "end": { "line": 4, diff --git a/test/fixtures/tree/task-list-unordered-dash.json b/test/fixtures/tree/task-list-unordered-dash.json index 3a20ea406..2ecc9a537 100644 --- a/test/fixtures/tree/task-list-unordered-dash.json +++ b/test/fixtures/tree/task-list-unordered-dash.json @@ -207,8 +207,8 @@ "position": { "start": { "line": 4, - "column": 3, - "offset": 63 + "column": 5, + "offset": 65 }, "end": { "line": 4, @@ -222,8 +222,8 @@ "position": { "start": { "line": 4, - "column": 3, - "offset": 63 + "column": 5, + "offset": 65 }, "end": { "line": 4, diff --git a/test/fixtures/tree/task-list-unordered-dash.nogfm.json b/test/fixtures/tree/task-list-unordered-dash.nogfm.json index 78212d025..2859b0111 100644 --- a/test/fixtures/tree/task-list-unordered-dash.nogfm.json +++ b/test/fixtures/tree/task-list-unordered-dash.nogfm.json @@ -318,8 +318,8 @@ "position": { "start": { "line": 4, - "column": 3, - "offset": 63 + "column": 5, + "offset": 65 }, "end": { "line": 4, @@ -333,8 +333,8 @@ "position": { "start": { "line": 4, - "column": 3, - "offset": 63 + "column": 5, + "offset": 65 }, "end": { "line": 4, diff --git a/test/fixtures/tree/task-list-unordered-plus.json b/test/fixtures/tree/task-list-unordered-plus.json index 3a20ea406..2ecc9a537 100644 --- a/test/fixtures/tree/task-list-unordered-plus.json +++ b/test/fixtures/tree/task-list-unordered-plus.json @@ -207,8 +207,8 @@ "position": { "start": { "line": 4, - "column": 3, - "offset": 63 + "column": 5, + "offset": 65 }, "end": { "line": 4, @@ -222,8 +222,8 @@ "position": { "start": { "line": 4, - "column": 3, - "offset": 63 + "column": 5, + "offset": 65 }, "end": { "line": 4, diff --git a/test/fixtures/tree/task-list-unordered-plus.nogfm.json b/test/fixtures/tree/task-list-unordered-plus.nogfm.json index 78212d025..2859b0111 100644 --- a/test/fixtures/tree/task-list-unordered-plus.nogfm.json +++ b/test/fixtures/tree/task-list-unordered-plus.nogfm.json @@ -318,8 +318,8 @@ "position": { "start": { "line": 4, - "column": 3, - "offset": 63 + "column": 5, + "offset": 65 }, "end": { "line": 4, @@ -333,8 +333,8 @@ "position": { "start": { "line": 4, - "column": 3, - "offset": 63 + "column": 5, + "offset": 65 }, "end": { "line": 4,